Skip to content

Commit e5fd5ca

Browse files
committed
mockStore now passes exceptions.
For example instead of the former meaningless and misleading error reported, you now see the reason why your tests failed: fetchPages 1) creates FETCH_PAGES_SUCCESS when fetching pages has been done 0 passing (2s) 1 failing 1) fetchPages creates FETCH_PAGES_SUCCESS when fetching pages has been done: Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test. ------------------------------------------------------------------------------------------------ fetchPages 1) creates FETCH_PAGES_SUCCESS when fetching pages has been done 0 passing (47ms) 1 failing 1) fetchPages creates FETCH_PAGES_SUCCESS when fetching pages has been done: AssertionError: { type: 'FETCH_PAGES_SUCCESS', pages: [ { id: '5628946bd0771c0e054ec2d5' }, { id: '5628946bd0771c0e054ec2d6' } ] } deepEqual { type: 'FETCH_PAGES_SUCCESS', pages: {} } + expected - actual { - "pages": [ - { - "id": "5628946bd0771c0e054ec2d5" - } - { - "id": "5628946bd0771c0e054ec2d6" - } - ] + "pages": {} "type": "FETCH_PAGES_SUCCESS" }
1 parent 8cb6218 commit e5fd5ca

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

docs/recipes/WritingTests.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,16 @@ function mockStore(getState, expectedActions, done) {
131131

132132
dispatch(action) {
133133
const expectedAction = expectedActions.shift();
134-
expect(action).toEqual(expectedAction);
135-
if (done && !expectedActions.length) {
136-
done();
134+
135+
try {
136+
expect(action).toEqual(expectedAction);
137+
if (done && !expectedActions.length) {
138+
done();
139+
}
140+
return action;
141+
} catch (e) {
142+
done(e);
137143
}
138-
return action;
139144
}
140145
}
141146
}

0 commit comments

Comments
 (0)