|
| 1 | +import {expect} from 'chai' |
| 2 | +import sinon from 'sinon' |
| 3 | +import createReducer from '../src/createReducer' |
| 4 | +import composeReducers from '../src/composeReducers' |
| 5 | +import createMiddleware from '../src/createMiddleware' |
| 6 | +import composeMiddleware from '../src/composeMiddleware' |
| 7 | +import createPluggableMiddleware from '../src/createPluggableMiddleware' |
| 8 | + |
| 9 | +/* eslint-disable no-console */ |
| 10 | +/* eslint-env node */ |
| 11 | + |
| 12 | +describe('dev mode warnings', () => { |
| 13 | + let origNodeEnv |
| 14 | + before(() => { |
| 15 | + origNodeEnv = process.env.NODE_ENV |
| 16 | + process.env.NODE_ENV = '' |
| 17 | + }) |
| 18 | + after(() => process.env.NODE_ENV = origNodeEnv) |
| 19 | + beforeEach(() => { |
| 20 | + sinon.spy(console, 'error') |
| 21 | + }) |
| 22 | + afterEach(() => { |
| 23 | + console.error.restore() |
| 24 | + }) |
| 25 | + describe('createReducer', () => { |
| 26 | + it('warns if any actionHandlers are not functions', () => { |
| 27 | + createReducer({hello: 'world'}) |
| 28 | + expect(console.error.called).to.be.true |
| 29 | + }) |
| 30 | + it("doesn't warn if all actionHandlers are functions", () => { |
| 31 | + createReducer({hello: () => 'world'}) |
| 32 | + expect(console.error.called).to.be.false |
| 33 | + }) |
| 34 | + }) |
| 35 | + describe('composeReducers', () => { |
| 36 | + it('warns if any reducers are not functions', () => { |
| 37 | + composeReducers(() => {}, 'hello') |
| 38 | + expect(console.error.called).to.be.true |
| 39 | + }) |
| 40 | + it("doesn't warn if all actionHandlers are functions", () => { |
| 41 | + composeReducers(() => {}) |
| 42 | + expect(console.error.called).to.be.false |
| 43 | + }) |
| 44 | + }) |
| 45 | + describe('createMiddleware', () => { |
| 46 | + it('warns if any actionHandlers are not functions', () => { |
| 47 | + createMiddleware({hello: 'world'}) |
| 48 | + expect(console.error.called).to.be.true |
| 49 | + }) |
| 50 | + it("doesn't warn if all actionHandlers are functions", () => { |
| 51 | + createMiddleware({hello: () => 'world'}) |
| 52 | + expect(console.error.called).to.be.false |
| 53 | + }) |
| 54 | + }) |
| 55 | + describe('composeMiddleware', () => { |
| 56 | + it('warns if any reducers are not functions', () => { |
| 57 | + composeMiddleware(() => {}, 'hello') |
| 58 | + expect(console.error.called).to.be.true |
| 59 | + }) |
| 60 | + it("doesn't warn if all actionHandlers are functions", () => { |
| 61 | + composeMiddleware(() => {}) |
| 62 | + expect(console.error.called).to.be.false |
| 63 | + }) |
| 64 | + }) |
| 65 | + describe('createPluggableMiddleware', () => { |
| 66 | + it('warns if any reducers are not functions', () => { |
| 67 | + const middleware = createPluggableMiddleware('hello') |
| 68 | + expect(console.error.called).to.be.true |
| 69 | + console.error.reset() |
| 70 | + middleware.replaceMiddleware('world') |
| 71 | + expect(console.error.called).to.be.true |
| 72 | + }) |
| 73 | + it("doesn't warn if all actionHandlers are functions", () => { |
| 74 | + const middleware = createPluggableMiddleware(() => {}) |
| 75 | + expect(console.error.called).to.be.false |
| 76 | + middleware.replaceMiddleware(() => () => () => 'world') |
| 77 | + expect(console.error.called).to.be.false |
| 78 | + }) |
| 79 | + }) |
| 80 | +}) |
0 commit comments