|
1 | 1 | import { expect } from 'chai'; |
2 | | - |
3 | | -import { repeat } from 'helpers'; |
| 2 | +import sinon from 'sinon'; |
4 | 3 |
|
5 | 4 | import { applyMiddleware, createStore } from 'redux'; |
6 | 5 |
|
7 | | -import sinon from 'sinon'; |
8 | | - |
9 | | -import createLogger from '../src'; |
| 6 | +import { repeat } from 'helpers'; |
| 7 | +import logger, { createLogger } from '../src'; |
10 | 8 |
|
11 | 9 | context(`Helpers`, () => { |
12 | | - describe(`'repeat'`, () => { |
| 10 | + describe(`repeat`, () => { |
13 | 11 | it(`should repeat a string the number of indicated times`, () => { |
14 | 12 | expect(repeat(`teacher`, 3)).to.equal(`teacherteacherteacher`); |
15 | 13 | }); |
16 | 14 | }); |
17 | 15 | }); |
18 | 16 |
|
19 | | -context('createLogger', () => { |
20 | | - describe('initialization', () => { |
| 17 | +context(`default logger`, () => { |
| 18 | + describe(`init`, () => { |
21 | 19 | beforeEach(() => { |
22 | | - sinon.spy(console, 'error'); |
| 20 | + sinon.spy(console, `error`); |
23 | 21 | }); |
24 | 22 |
|
25 | 23 | afterEach(() => { |
26 | 24 | console.error.restore(); |
27 | 25 | }); |
28 | 26 |
|
29 | | - it('should log an error if the function is passed to applyMiddleware', () => { |
| 27 | + it(`should be ok`, () => { |
| 28 | + const store = createStore(() => ({}), applyMiddleware(logger)); |
| 29 | + |
| 30 | + store.dispatch({ type: `foo` }); |
| 31 | + sinon.assert.notCalled(console.error); |
| 32 | + }); |
| 33 | + }); |
| 34 | +}); |
| 35 | + |
| 36 | +context(`createLogger`, () => { |
| 37 | + describe(`init`, () => { |
| 38 | + beforeEach(() => { |
| 39 | + sinon.spy(console, `error`); |
| 40 | + }); |
| 41 | + |
| 42 | + afterEach(() => { |
| 43 | + console.error.restore(); |
| 44 | + }); |
| 45 | + |
| 46 | + it(`should throw error if passed direct to applyMiddleware`, () => { |
30 | 47 | const store = createStore(() => ({}), applyMiddleware(createLogger)); |
31 | | - store.dispatch({ type: 'foo' }); |
| 48 | + |
| 49 | + store.dispatch({ type: `foo` }); |
32 | 50 | sinon.assert.calledOnce(console.error); |
33 | 51 | }); |
34 | 52 |
|
35 | | - it('should not log an error if the correct function is passed', () => { |
| 53 | + it(`should be ok`, () => { |
36 | 54 | const store = createStore(() => ({}), applyMiddleware(createLogger())); |
37 | | - store.dispatch({ type: 'foo' }); |
| 55 | + |
| 56 | + store.dispatch({ type: `foo` }); |
38 | 57 | sinon.assert.notCalled(console.error); |
39 | 58 | }); |
40 | 59 | }); |
|
0 commit comments