Skip to content

Commit 9ad3166

Browse files
committed
Add more specs/reorganize
1 parent 5b1b79a commit 9ad3166

File tree

3 files changed

+51
-24
lines changed

3 files changed

+51
-24
lines changed

spec/helpers.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect } from 'chai';
2+
3+
import { repeat } from '../src/helpers';
4+
5+
context(`Helpers`, () => {
6+
describe(`repeat`, () => {
7+
it(`should repeat a string the number of indicated times`, () => {
8+
expect(repeat(`teacher`, 3)).to.equal(`teacherteacherteacher`);
9+
});
10+
});
11+
});

spec/index.spec.js

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
import { expect } from 'chai';
21
import sinon from 'sinon';
3-
42
import { applyMiddleware, createStore } from 'redux';
53

6-
import { repeat } from 'helpers';
74
import logger, { createLogger } from '../src';
85

9-
context(`Helpers`, () => {
10-
describe(`repeat`, () => {
11-
it(`should repeat a string the number of indicated times`, () => {
12-
expect(repeat(`teacher`, 3)).to.equal(`teacherteacherteacher`);
13-
});
14-
});
15-
});
16-
176
context(`default logger`, () => {
187
describe(`init`, () => {
198
beforeEach(() => {
@@ -34,27 +23,54 @@ context(`default logger`, () => {
3423
});
3524

3625
context(`createLogger`, () => {
37-
describe(`init`, () => {
26+
beforeEach(() => {
27+
sinon.spy(console, `error`);
28+
sinon.spy(console, 'log');
29+
});
30+
31+
afterEach(() => {
32+
console.error.restore();
33+
console.log.restore();
34+
});
35+
36+
let store;
37+
38+
context('mistakenly passed directly to applyMiddleware', () => {
3839
beforeEach(() => {
39-
sinon.spy(console, `error`);
40+
store = createStore(() => ({}), applyMiddleware(createLogger));
4041
});
4142

42-
afterEach(() => {
43-
console.error.restore();
43+
it('should log error', () => {
44+
sinon.assert.calledOnce(console.error);
4445
});
4546

46-
it(`should throw error if passed direct to applyMiddleware`, () => {
47-
const store = createStore(() => ({}), applyMiddleware(createLogger));
48-
47+
it('should create an empty middleware', () => {
4948
store.dispatch({ type: `foo` });
50-
sinon.assert.calledOnce(console.error);
49+
sinon.assert.notCalled(console.log);
5150
});
51+
});
5252

53-
it(`should be ok`, () => {
54-
const store = createStore(() => ({}), applyMiddleware(createLogger()));
53+
context('options.logger undefined or null', () => {
54+
beforeEach(() => {
55+
const logger = createLogger({ logger: null });
56+
store = createStore(() => ({}), applyMiddleware(logger));
57+
});
5558

56-
store.dispatch({ type: `foo` });
57-
sinon.assert.notCalled(console.error);
59+
it('should create an empty middleware', () => {
60+
store.dispatch({ type: 'foo' });
61+
sinon.assert.notCalled(console.log);
62+
});
63+
});
64+
65+
context('options.predicate returns false', () => {
66+
beforeEach(() => {
67+
const logger = createLogger({ predicate: () => false });
68+
store = createStore(() => ({}), applyMiddleware(logger));
69+
});
70+
71+
it('should not log', () => {
72+
store.dispatch({ type: 'foo' });
73+
sinon.assert.notCalled(console.log);
5874
});
5975
});
6076
});

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function createLogger(options = {}) {
7979

8080
return ({ getState }) => next => (action) => {
8181
// Exit early if predicate function returns 'false'
82-
if (shouldNotLog(getState, action)) return next(action);
82+
if (shouldNotLog(options, getState, action)) return next(action);
8383

8484
const started = timer.now();
8585
const startedTime = new Date();

0 commit comments

Comments
 (0)