|
| 1 | +/* eslint-disable */ |
| 2 | +import configureMockStore from 'redux-mock-store'; |
| 3 | +import { toggleMiddleware } from '../../src/middleware/toggle'; |
| 4 | + |
| 5 | +const next = jest.fn(); |
| 6 | +const mockStore = configureMockStore(); |
| 7 | + |
| 8 | +describe('Toggle middleware', () => { |
| 9 | + it('should dispatch TOGGLE_JS when the payload is `js`', () => { |
| 10 | + const mockDispatch = jest.fn(); |
| 11 | + |
| 12 | + const store = mockStore({ |
| 13 | + js: 'es5', |
| 14 | + dispatch: mockDispatch, |
| 15 | + }); |
| 16 | + const action = { type: 'TOGGLE', payload: 'js' }; |
| 17 | + |
| 18 | + toggleMiddleware(store)(next)(action); |
| 19 | + |
| 20 | + expect(store.getActions()[0]).toEqual({ |
| 21 | + type: 'TOGGLE_JS', |
| 22 | + payload: 'es6', |
| 23 | + }); |
| 24 | + |
| 25 | + expect(next).toHaveBeenCalled(); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should dispatch TOGGLE_JS when the payload is `js`', () => { |
| 29 | + const mockDispatch = jest.fn(); |
| 30 | + |
| 31 | + const store = mockStore({ |
| 32 | + js: 'es6', |
| 33 | + dispatch: mockDispatch, |
| 34 | + }); |
| 35 | + const action = { type: 'TOGGLE', payload: 'js' }; |
| 36 | + |
| 37 | + toggleMiddleware(store)(next)(action); |
| 38 | + |
| 39 | + expect(store.getActions()[0]).toEqual({ |
| 40 | + type: 'TOGGLE_JS', |
| 41 | + payload: 'es5', |
| 42 | + }); |
| 43 | + |
| 44 | + expect(next).toHaveBeenCalled(); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should dispatch TOGGLE_MODE when the payload is `mode`', () => { |
| 48 | + const mockDispatch = jest.fn(); |
| 49 | + |
| 50 | + const store = mockStore({ |
| 51 | + mode: 'dark', |
| 52 | + dispatch: mockDispatch, |
| 53 | + }); |
| 54 | + const action = { type: 'TOGGLE', payload: 'mode' }; |
| 55 | + |
| 56 | + toggleMiddleware(store)(next)(action); |
| 57 | + |
| 58 | + expect(store.getActions()[0]).toEqual({ |
| 59 | + type: 'TOGGLE_MODE', |
| 60 | + payload: 'light', |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should dispatch TOGGLE_MODE when the payload is `mode`', () => { |
| 65 | + const mockDispatch = jest.fn(); |
| 66 | + |
| 67 | + const store = mockStore({ |
| 68 | + mode: 'light', |
| 69 | + dispatch: mockDispatch, |
| 70 | + }); |
| 71 | + const action = { type: 'TOGGLE', payload: 'mode' }; |
| 72 | + |
| 73 | + toggleMiddleware(store)(next)(action); |
| 74 | + |
| 75 | + expect(store.getActions()[0]).toEqual({ |
| 76 | + type: 'TOGGLE_MODE', |
| 77 | + payload: 'dark', |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should return _next_ when the action is not TOGGLE', () => { |
| 82 | + const store = mockStore({}); |
| 83 | + const action = { type: 'ERROR' }; |
| 84 | + |
| 85 | + toggleMiddleware(store)(next)(action); |
| 86 | + |
| 87 | + expect(store.getActions()[0]).toBeFalsy(); |
| 88 | + }); |
| 89 | +}); |
0 commit comments