nexshop-web-skeleton
Version:
Nexshop Web Skeleton Project
46 lines (35 loc) • 1.68 kB
JavaScript
import React from 'react';
import {expect} from 'chai';
import sinon from "sinon";
import reduxLoadingMiddleware from "../../src/middlewares/redux-loading-middleware";
describe('Redux Loading Middleware', () => {
const spyNext = sinon.spy();
const spyDispatch = sinon.spy();
let mockStore;
beforeEach(() => {
mockStore = {
dispatch: spyDispatch,
};
const action = async function FETCH_SOME_LIST() {};
reduxLoadingMiddleware(mockStore)(spyNext)(action);
});
afterEach(() => {
spyNext.reset();
spyDispatch.reset();
});
it('calls spyDispatch with {status: true, id: "FETCH_SOME_LIST"} when async action is called', () => {
expect(mockStore.dispatch.calledWith({type: 'FETCH_STATUS', status: true, id: 'FETCH_SOME_LIST'})).to.be.true;
const action = {type: 'FETCH_SOME_LIST_SUCCESS'};
reduxLoadingMiddleware(mockStore)(spyNext)(action);
});
it('calls spyDispatch with {status: false, id: "FETCH_SOME_LIST"} when SUCCESS action is called', () => {
const action = {type: 'FETCH_SOME_LIST_SUCCESS'};
reduxLoadingMiddleware(mockStore)(spyNext)(action);
expect(mockStore.dispatch.calledWith({type: 'FETCH_STATUS', status: false, id: 'FETCH_SOME_LIST'})).to.be.true;
});
it('calls spyDispatch with {status: false, id: "FETCH_SOME_LIST"} when FAIL action is called', () => {
const action = {type: 'FETCH_SOME_LIST_FAIL'};
reduxLoadingMiddleware(mockStore)(spyNext)(action);
expect(mockStore.dispatch.calledWith({type: 'FETCH_STATUS', status: false, id: 'FETCH_SOME_LIST'})).to.be.true;
});
});