Skip to content

Commit 4118dc6

Browse files
committed
Merge pull request #930 from haihappen/patch-1
Improves Writing Tests doc.
2 parents 40ae17c + e5fd5ca commit 4118dc6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

docs/recipes/WritingTests.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ const middlewares = [thunk];
113113
/**
114114
* Creates a mock of Redux store with middleware.
115115
*/
116-
function mockStore(getState, expectedActions, onLastAction) {
116+
function mockStore(getState, expectedActions, done) {
117117
if (!Array.isArray(expectedActions)) {
118118
throw new Error('expectedActions should be an array of expected actions.');
119119
}
120-
if (typeof onLastAction !== 'undefined' && typeof onLastAction !== 'function') {
121-
throw new Error('onLastAction should either be undefined or function.');
120+
if (typeof done !== 'undefined' && typeof done !== 'function') {
121+
throw new Error('done should either be undefined or function.');
122122
}
123123

124124
function mockStoreWithoutMiddleware() {
@@ -131,11 +131,16 @@ function mockStore(getState, expectedActions, onLastAction) {
131131

132132
dispatch(action) {
133133
const expectedAction = expectedActions.shift();
134-
expect(action).toEqual(expectedAction);
135-
if (onLastAction && !expectedActions.length) {
136-
onLastAction();
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)