UNPKG

reducer-tester

Version:
99 lines 3.16 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var _1 = __importDefault(require(".")); var noop = function () { }; var reducer = function (state, action) { if (state === void 0) { state = {}; } if (action.payload) { return { result: action.payload }; } return state; }; var itSpy; var state = {}; beforeEach(function () { // @ts-ignore itSpy = jest.spyOn(global, 'it').mockImplementation(noop); }); afterEach(function () { itSpy.mockRestore(); }); test('throws an invariant if tests is not Array', function () { expect(function () { // @ts-ignore _1.default({ reducer: reducer, state: state, tests: null }); }).toThrowErrorMatchingSnapshot(); }); test('throws an invariant if type property is not exist', function () { expect(function () { // @ts-ignore _1.default({ reducer: reducer, state: state, tests: [{ typo: 'typo' }] }); }).toThrowErrorMatchingSnapshot(); }); test('throws an invariant if state property is not exist', function () { expect(function () { // @ts-ignore _1.default({ reducer: reducer, tests: [] }); }).toThrowErrorMatchingSnapshot(); }); test('can provide an object for tests', function () { var title = 'reducer-test'; _1.default({ reducer: reducer, state: state, tests: [{ type: title, payload: 'payload' }], }); expect(itSpy).toHaveBeenCalledTimes(2); expect(itSpy).toHaveBeenCalledWith(title, expect.any(Function)); expect(itSpy).toHaveBeenCalledWith('handle initial state', expect.any(Function)); }); test('can provide empty array for tests', function () { _1.default({ tests: [], reducer: reducer, state: state }); expect(itSpy).toHaveBeenCalledTimes(1); }); test('can provide initialTest', function () { _1.default({ reducer: reducer, state: state, tests: [{ type: 'test' }], initialTest: true, }); expect(itSpy).toHaveBeenCalledTimes(2); expect(itSpy).toHaveBeenCalledWith('handle initial state', expect.any(Function)); }); test('not handle initial state with initialTest = false', function () { _1.default({ reducer: reducer, state: state, tests: [{ type: 'test' }], initialTest: false, }); expect(itSpy).toHaveBeenCalledTimes(1); }); test('can provide titlePrefix', function () { var title = 'reducer'; _1.default({ reducer: reducer, state: state, titlePrefix: 'handle ', tests: [{ type: title, payload: 'payload' }], }); expect(itSpy).toHaveBeenCalledTimes(2); expect(itSpy).toHaveBeenCalledWith('handle reducer', expect.any(Function)); }); // haha... jest work :) _1.default({ reducer: reducer, state: state, tests: [{ type: 'work', payload: 'payload' }], }); _1.default({ reducer: reducer, state: state, titlePrefix: 'handle ', tests: [{ type: 'work', payload: 'payload' }], }); //# sourceMappingURL=index.test.js.map