redux-mock-store-await-actions
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="2.0.1"></a> | ||
## [2.0.1](https://github.com/moxystudio/redux-mock-store-await-actions/compare/v2.0.0...v2.0.1) (2018-02-07) | ||
### Bug Fixes | ||
* remove store subscription and clear timeout ([#21](https://github.com/moxystudio/redux-mock-store-await-actions/issues/21)) ([3384a42](https://github.com/moxystudio/redux-mock-store-await-actions/commit/3384a42)) | ||
<a name="2.0.0"></a> | ||
@@ -7,0 +17,0 @@ # [2.0.0](https://github.com/moxystudio/redux-mock-store-await-actions/compare/v1.0.0...v2.0.0) (2018-02-01) |
@@ -72,3 +72,6 @@ 'use strict'; | ||
promise && resolve(promise); | ||
if (promise) { | ||
teardown(); | ||
resolve(promise); | ||
} | ||
}); | ||
@@ -75,0 +78,0 @@ |
{ | ||
"name": "redux-mock-store-await-actions", | ||
"description": "Waits for specific actions to be dispatched or a timeout expires.", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"keywords": [ | ||
@@ -52,3 +52,3 @@ "redux", | ||
"eslint": "^4.3.0", | ||
"eslint-config-moxy": "^4.1.0", | ||
"eslint-config-moxy": "^5.0.0", | ||
"husky": "^0.14.3", | ||
@@ -55,0 +55,0 @@ "jest": "^22.0.0", |
@@ -231,2 +231,3 @@ # redux-mock-store-await-actions | ||
} | ||
const hasLoginStart = storeActions.some((action) => action.type === 'LOGIN_START' && action.payload.username === 'my-username'); | ||
@@ -233,0 +234,0 @@ const hasFetchOrdersSuccess = storeActions.some((action) => action.type === 'FETCH_ORDERS_SUCCESS'); |
@@ -6,3 +6,3 @@ 'use strict'; | ||
const thunkMiddleware = require('redux-thunk').default; | ||
const assertError = require('./util/assertError'); | ||
const { assertError, spyOnUnsubscribe } = require('./util'); | ||
@@ -18,4 +18,3 @@ const { containing } = waitForActions.matchers; | ||
const asyncActionsCreator = (actions, timeout = 10) => (dispatch) => { | ||
const timeoutId = setTimeout(() => { | ||
clearTimeout(timeoutId); | ||
setTimeout(() => { | ||
actions.forEach((action) => dispatch(action)); | ||
@@ -29,3 +28,3 @@ }, timeout); | ||
jest.useRealTimers(); | ||
jest.clearAllMocks(); | ||
jest.restoreAllMocks(); | ||
}); | ||
@@ -64,2 +63,16 @@ | ||
it('should fulfill the promise when no actions are expected', async () => { | ||
const mockStore = createMockStore([thunkMiddleware]); | ||
const actions = [action1, action2, action3]; | ||
mockStore.dispatch(asyncActionsCreator(actions)); | ||
await waitForActions(mockStore, []); | ||
mockStore.clearActions(); | ||
mockStore.dispatch(asyncActionsCreator(actions)); | ||
await waitForActions(mockStore, [], { matcher: containing }); | ||
}); | ||
it('should reject the promise when an action creator is dispatched and the order of expected and dispatched actions mismatch', () => { | ||
@@ -117,11 +130,2 @@ const mockStore = createMockStore([thunkMiddleware]); | ||
it('should fulfill the promise when no actions are expected', async () => { | ||
const mockStore = createMockStore(); | ||
const actions = []; | ||
await waitForActions(mockStore, actions); | ||
expect(mockStore.getActions()).toEqual(actions); | ||
}); | ||
it('should reject the promise when expected actions are not received and timeout expires', () => { | ||
@@ -244,1 +248,67 @@ const mockStore = createMockStore(); | ||
}); | ||
it('should teardown correctly when promise fulfills', async () => { | ||
const mockStore = createMockStore([thunkMiddleware]); | ||
const clearTimeoutSpy = jest.spyOn(global, 'clearTimeout'); | ||
const getUnsubcribeSpy = spyOnUnsubscribe(mockStore); | ||
mockStore.dispatch(asyncActionsCreator([action1])); | ||
await waitForActions(mockStore, action1); | ||
expect(clearTimeoutSpy).toHaveBeenCalledTimes(1); | ||
expect(getUnsubcribeSpy()).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should teardown correctly when promise rejects via timeout', async () => { | ||
expect.assertions(1); | ||
const mockStore = createMockStore([thunkMiddleware]); | ||
const getUnsubcribeSpy = spyOnUnsubscribe(mockStore); | ||
mockStore.dispatch(asyncActionsCreator([action1])); | ||
try { | ||
await waitForActions(mockStore, [action1, action2]); | ||
} catch (err) { | ||
expect(getUnsubcribeSpy()).toHaveBeenCalledTimes(1); | ||
} | ||
}); | ||
it('should teardown correctly when promise rejects via cancelation', async () => { | ||
expect.assertions(2); | ||
const mockStore = createMockStore([thunkMiddleware]); | ||
const clearTimeoutSpy = jest.spyOn(global, 'clearTimeout'); | ||
const getUnsubcribeSpy = spyOnUnsubscribe(mockStore); | ||
mockStore.dispatch(asyncActionsCreator([action1])); | ||
const promise = waitForActions(mockStore, [action1, action2]); | ||
setTimeout(() => promise.cancel(), 10); | ||
try { | ||
await promise; | ||
} catch (err) { | ||
expect(getUnsubcribeSpy()).toHaveBeenCalledTimes(1); | ||
expect(clearTimeoutSpy).toHaveBeenCalledTimes(1); | ||
} | ||
}); | ||
it('should teardown correctly when promise rejects with mismatch', async () => { | ||
expect.assertions(2); | ||
const mockStore = createMockStore([thunkMiddleware]); | ||
const clearTimeoutSpy = jest.spyOn(global, 'clearTimeout'); | ||
const getUnsubcribeSpy = spyOnUnsubscribe(mockStore); | ||
mockStore.dispatch(asyncActionsCreator([action1])); | ||
try { | ||
await waitForActions(mockStore, action2); | ||
} catch (err) { | ||
expect(getUnsubcribeSpy()).toHaveBeenCalledTimes(1); | ||
expect(clearTimeoutSpy).toHaveBeenCalledTimes(1); | ||
} | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27468
13
334
254
0