|
| 1 | +import * as issueActions from "./issueActions"; |
| 2 | +import * as types from "./actionTypes"; |
| 3 | +import { issues } from "../../tools/mockData"; |
| 4 | +import thunk from "redux-thunk"; |
| 5 | +import fetchMock from "fetch-mock"; |
| 6 | +import configureMockStore from "redux-mock-store"; |
| 7 | + |
| 8 | +// Test an async action |
| 9 | +const middleware = [thunk]; |
| 10 | +const mockStore = configureMockStore(middleware); |
| 11 | + |
| 12 | +describe("Tests Async Actions", () => { |
| 13 | + afterEach(() => { |
| 14 | + fetchMock.restore(); |
| 15 | + }); |
| 16 | + |
| 17 | + describe("Load Issues Thunk", () => { |
| 18 | + it("creates BEGIN_API_CALL and LOAD_ISSUES_SUCCESS when loading issues", () => { |
| 19 | + fetchMock.mock("*", { |
| 20 | + body: issues, |
| 21 | + headers: { "content-type": "application/json" } |
| 22 | + }); |
| 23 | + |
| 24 | + const expectedActions = [ |
| 25 | + { type: types.BEGIN_API_CALL }, |
| 26 | + { type: types.LOAD_ISSUES_SUCCESS, issues } |
| 27 | + ]; |
| 28 | + |
| 29 | + const store = mockStore({ issues: [] }); |
| 30 | + return store.dispatch(issueActions.loadIssues()).then(() => { |
| 31 | + expect(store.getActions()).toEqual(expectedActions); |
| 32 | + }); |
| 33 | + }); |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +describe("Tests Issue Actions", () => { |
| 38 | + it("tests LOAD_ISSUES_SUCCESS action", () => { |
| 39 | + //arrange |
| 40 | + const expectedAction = { |
| 41 | + type: types.LOAD_ISSUES_SUCCESS, |
| 42 | + issues |
| 43 | + }; |
| 44 | + |
| 45 | + //act |
| 46 | + const action = issueActions.loadIssuesSuccess(issues); |
| 47 | + |
| 48 | + //assert |
| 49 | + expect(action).toEqual(expectedAction); |
| 50 | + }); |
| 51 | +}); |
0 commit comments