
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
redux-asserts
Advanced tools
Functions to assert dispatched actions in redux. These functions are aimed at making integration testing with redux easier by abstracting away the need to manage and listen to the store's actions.
A redux store is created with a wrapper that listens for actions dispatched to it. The assert functions
return a Promise which resolves when all expected action types are received, or rejects when an unexpected
action type is received.
npm install redux-asserts --save-dev
Check out the repository, run npm install, then run npm test.
In your testing code:
import configureTestStore from 'redux-asserts';
import rootReducer from '../reducers';
Create a redux store for testing using configureTestStore. Then use that
store's createListenForActions and createListenForActions functions to
create the listenForActions and dispatchThen functions respectively.
Asserts that a list of actions were called during or after the execution of the callback,
then resolves the Promise. The Promise will reject on an assertion error, but
note that there are cases where the Promise may resolve earlier than the user would want,
or the Promise may never be resolved or rejected.
This function takes two required arguments:
listenForActions(actionTypes, callback) => Promise
Promise may never resolve. If there are fewer action types, the Promise will
resolve since all expected action types were asserted. If at any point there is
an unexpected action type the Promise will reject.Promise which will be resolved or rejected after the
action types are asserted.Example:
describe('cart rendering', () => {
let listenForActions, store;
beforeEach(() => {
store = configureTestStore(rootReducer);
listenForActions = store.createListenForActions();
});
it('clicks the add to cart button', done => {
listenForActions([UPDATE_CART_ITEMS, UPDATE_CART_VISIBILITY], () => {
// Click the Update cart button
let button = TestUtils.findRenderedDOMComponentWithClass(component, "add-to-cart");
TestUtils.Simulate.click(button);
}).then(state => {
done();
});
});
});
This runs the function passed into listenForActions, then waits while
asserting the types dispatched. If the types are asserted
to be dispatched, the promise resolves.
See also the examples in the test directory.
Dispatches an action or action creator, then asserts a list of action types were called
after the dispatch of the action, then resolves the Promise. The Promise will
reject on an assertion error, but there are cases where the Promise
may resolve earlier than the user would want, or the Promise may never be resolved or rejected.
Note that this function is exactly the same as listenForActions but where the callback is
dispatch(action());
This function takes two required arguments:
dispatchThen(action, actionTypes) => Promise
dispatch().action, but the types may be
in any order. If there are more action types being expected than actions, the
Promise may never resolve. If there are fewer action types, the Promise will
resolve since all expected action types were asserted. If at any point there is
an unexpected action type the Promise will reject.Promise which will be resolved or rejected after the
action types are asserted.Example:
describe('course reducers', () => {
let dispatchThen, store;
beforeEach(() => {
// Create a redux store for testing
store = configureTestStore(rootReducer);
// Create the dispatchThen function we use below
dispatchThen = store.createDispatchThen(state => state.courseList);
});
it('should fetch a list of courses successfully', done => {
dispatchThen(fetchCourseList(), [REQUEST_COURSE_LIST, RECEIVE_COURSE_LIST_SUCCESS]).then(courseState => {
assert.deepEqual(courseState.courseList, COURSE_LIST_DATA);
assert.equal(courseState.courseListStatus, FETCH_SUCCESS);
done();
});
});
});
This dispatches the fetchCourseList action, asserts that the two action
types REQUEST_COURSE_LIST and RECEIVE_COURSE_LIST_SUCCESS were the only
actions dispatched, then the promise resolves with the given state.
See also the examples in the test directory.
FAQs
Functions to assert dispatched actions in redux
The npm package redux-asserts receives a total of 1,223 weekly downloads. As such, redux-asserts popularity was classified as popular.
We found that redux-asserts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.