UNPKG

opds-web-client

Version:
39 lines (38 loc) 1.91 kB
"use strict"; jest.dontMock("../state"); jest.dontMock("../reducers/index"); jest.dontMock("../reducers/collection"); jest.dontMock("../reducers/book"); var fetchCollectionAndBook; var createFetchCollectionAndBook = jest.genMockFunction(); createFetchCollectionAndBook.mockImplementation(function (collectionUrl, bookUrl) { return fetchCollectionAndBook; }); var dispatch = function () { }; var initialState = "initial state"; var alteredState = "state with collection and book"; var testState = initialState; jest.setMock("../components/mergeRootProps", { createFetchCollectionAndBook: createFetchCollectionAndBook }); jest.setMock("../store", { default: function () { return { dispatch: dispatch, getState: function () { return testState; } }; } }); var state_1 = require("../state"); describe("buildInitialState", function () { var collectionUrl = "collection url"; var bookUrl = "book url"; beforeEach(function () { fetchCollectionAndBook = jest.genMockFunction(); fetchCollectionAndBook.mockReturnValue(new Promise(function (resolve, reject) { testState = alteredState; resolve({ collectionData: null, bookData: null }); })); createFetchCollectionAndBook.mockClear(); }); it("fetches given collection and book into state", function (done) { state_1.default(collectionUrl, bookUrl).then(function (state) { expect(createFetchCollectionAndBook.mock.calls.length).toBe(1); expect(createFetchCollectionAndBook.mock.calls[0][0]).toBe(dispatch); expect(fetchCollectionAndBook.mock.calls.length).toBe(1); expect(fetchCollectionAndBook.mock.calls[0][0]).toBe(collectionUrl); expect(fetchCollectionAndBook.mock.calls[0][1]).toBe(bookUrl); expect(state).toBe(alteredState); done(); }).catch(function (err) { return done(err); }); }); });