Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-mock-store

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-mock-store - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

23

lib/index.js

@@ -18,7 +18,10 @@ 'use strict';

function configureStore(middlewares) {
function configureStore() {
var middlewares = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
return function mockStore(_getState, expectedActions, done) {
if (!Array.isArray(expectedActions)) {
throw new Error('expectedActions should be an array of expected actions.');
if (!expectedActions) {
throw new Error('expectedActions should be an expected action or an array of actions.');
} else if (!Array.isArray(expectedActions)) {
expectedActions = [expectedActions];
}

@@ -31,3 +34,3 @@

function mockStoreWithoutMiddleware() {
return {
var self = {
getState: function getState() {

@@ -38,2 +41,6 @@ return typeof _getState === 'function' ? _getState() : _getState;

dispatch: function dispatch(action) {
if (action instanceof Function) {
return action(self);
}
var expectedAction = expectedActions.shift();

@@ -48,6 +55,12 @@

} catch (e) {
done(e);
if (done) {
done(e);
} else {
throw e;
}
}
}
};
return self;
}

@@ -54,0 +67,0 @@

{
"name": "redux-mock-store",
"version": "0.0.2",
"version": "0.0.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -5,3 +5,3 @@ [![Circle CI](https://circleci.com/gh/arnaudbenard/redux-mock-store/tree/master.svg?style=svg)](https://circleci.com/gh/arnaudbenard/redux-mock-store/tree/master)

A mock store for your testing your redux app
A mock store for your testing your redux async action creators and middleware

@@ -8,0 +8,0 @@ ## Install

@@ -10,7 +10,13 @@ import expect from 'expect';

it('throws an error if expectedActions is not an array', () => {
expect(() => mockStore({}, {}))
it('throws an error if expectedActions is not provided', () => {
expect(() => mockStore({}))
.toThrow(/expectedActions/);
});
it('converts a single expected action to an array', () => {
const store = mockStore({}, {});
expect(store).toExist();
});
it('throws an error if done is not a function or undefined', () => {

@@ -49,2 +55,23 @@ expect(() => mockStore({}, [], {}))

it('handles actions that return functions', () => {
const action = { type: 'ADD_ITEM' };
const store = mockStore({}, [action]);
store.dispatch(
({ dispatch }) => dispatch(action)
);
});
it('handles async actions', done => {
const clock = sinon.useFakeTimers();
const action = async ({ dispatch }) => {
const value = await Promise.resolve({ type: 'ASYNC' })
dispatch(value)
};
const store = mockStore({}, [{ type: 'ASYNC' }], done);
store.dispatch(action);
clock.tick(1);
clock.restore();
});
it('should call the middleware', (done) => {

@@ -51,0 +78,0 @@ const spy = sinon.spy();

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