@treet/redux-mock-store
v1.0.0
Published
Utilities for testing Redux action creators and middleware
Readme
@treet/redux-mock-store
Replacement for redux-mock-store and @jedmao/redux-mock-store that uses Redux 4. Unlike previously mentioned libraries, this one does not really mock an Redux store, but uses an actual Redux store that just has action logging middleware installed into it that allows you to inspect dispatched actions in test cases.
Installation
$ npm install --save-dev @treet/redux-mock-storeOr
$ yarn add --dev @treet/redux-mock-storeUsage
import { createAction, createReducer } from "@reduxjs/toolkit";
import { configureMockStore } from "@treet/redux-mock-store";
type AuthState = {
isAuthenticated: boolean;
};
type RootState = {
auth: AuthState;
};
const loginAction = createAction<void>("LOGIN");
const authReducer = createReducer<AuthState>(
{ isAuthenticated: false },
builder => {
builder.addCase(loginAction, (state) => {
state.isAuthenticated = true;
});
},
);
const mockStoreCreator = configureMockStore<RootState>({ auth: authReducer });
const mockStore = mockStoreCreator();
mockStore.dispatch(loginAction());
console.log(mockStore.getActions());