Socket
Socket
Sign inDemoInstall

redux-mock-store-await-actions

Package Overview
Dependencies
Maintainers
16
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-mock-store-await-actions - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

test/util/index.js

10

CHANGELOG.md

@@ -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)

5

index.js

@@ -72,3 +72,6 @@ 'use strict';

promise && resolve(promise);
if (promise) {
teardown();
resolve(promise);
}
});

@@ -75,0 +78,0 @@

4

package.json
{
"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);
}
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc