Skip to content

Commit

Permalink
fetchActions [nfc]: File a test under new "success" describe block.
Browse files Browse the repository at this point in the history
Soon, we'll add another test that's interested in a successful
fetch. After that, we'll add another section for when the fetch
fails.
  • Loading branch information
chrisbobbe committed Aug 7, 2020
1 parent 6b60f80 commit fb13098
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/message/__tests__/fetchActions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,27 @@ describe('fetchActions', () => {
},
});

test('message fetch success action is dispatched after successful fetch', async () => {
const store = mockStore<GlobalState, Action>(baseState);
describe('success', () => {
beforeEach(() => {
const response = {
messages: [message1, message2, message3],
result: 'success',
};
fetch.mockResponseSuccess(JSON.stringify(response));
});

const response = {
messages: [message1, message2, message3],
result: 'success',
};
fetch.mockResponseSuccess(JSON.stringify(response));
const store = mockStore<GlobalState, Action>(baseState);

await store.dispatch(
fetchMessages({ narrow: HOME_NARROW, anchor: 0, numBefore: 1, numAfter: 1 }),
);
const actions = store.getActions();
test('message fetch success action is dispatched', async () => {
await store.dispatch(
fetchMessages({ narrow: HOME_NARROW, anchor: 0, numBefore: 1, numAfter: 1 }),
);
const actions = store.getActions();

expect(actions).toHaveLength(2);
expect(actions[0].type).toBe('MESSAGE_FETCH_START');
expect(actions[1].type).toBe('MESSAGE_FETCH_COMPLETE');
expect(actions).toHaveLength(2);
expect(actions[0].type).toBe('MESSAGE_FETCH_START');
expect(actions[1].type).toBe('MESSAGE_FETCH_COMPLETE');
});
});

const BORING_RESPONSE = JSON.stringify({
Expand Down

0 comments on commit fb13098

Please sign in to comment.