Skip to content

Commit e6c039a

Browse files
committed
Add more specs/reorganize
1 parent a32491f commit e6c039a

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

spec/helpers.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ context('Helpers', () => {
1818
it('should format a time given a Date object', () => {
1919
const time = new Date('December 25, 1995 23:15:30');
2020
expect(formatTime(time)).to.equal('23:15:30.000');
21-
});
21+
});
2222
});
2323
});

spec/index.spec.js

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,54 @@ context('default logger', () => {
2222
});
2323

2424
context('createLogger', () => {
25-
describe('init', () => {
25+
beforeEach(() => {
26+
sinon.spy(console, 'error');
27+
sinon.spy(console, 'log');
28+
});
29+
30+
afterEach(() => {
31+
console.error.restore();
32+
console.log.restore();
33+
});
34+
35+
let store;
36+
37+
context('mistakenly passed directly to applyMiddleware', () => {
2638
beforeEach(() => {
27-
sinon.spy(console, 'error');
39+
store = createStore(() => ({}), applyMiddleware(createLogger));
2840
});
2941

30-
afterEach(() => {
31-
console.error.restore();
42+
it('should log error', () => {
43+
sinon.assert.calledOnce(console.error);
3244
});
3345

34-
it('should throw error if passed direct to applyMiddleware', () => {
35-
const store = createStore(() => ({}), applyMiddleware(createLogger));
46+
it('should create an empty middleware', () => {
47+
store.dispatch({ type: 'foo' });
48+
sinon.assert.notCalled(console.log);
49+
});
50+
});
51+
52+
context('options.logger undefined or null', () => {
53+
beforeEach(() => {
54+
const logger = createLogger({ logger: null });
55+
store = createStore(() => ({}), applyMiddleware(logger));
56+
});
3657

58+
it('should create an empty middleware', () => {
3759
store.dispatch({ type: 'foo' });
38-
sinon.assert.calledOnce(console.error);
60+
sinon.assert.notCalled(console.log);
3961
});
62+
});
4063

41-
it('should be ok', () => {
42-
const store = createStore(() => ({}), applyMiddleware(createLogger()));
64+
context('options.predicate returns false', () => {
65+
beforeEach(() => {
66+
const logger = createLogger({ predicate: () => false });
67+
store = createStore(() => ({}), applyMiddleware(logger));
68+
});
4369

70+
it('should not log', () => {
4471
store.dispatch({ type: 'foo' });
45-
sinon.assert.notCalled(console.error);
72+
sinon.assert.notCalled(console.log);
4673
});
4774
});
4875
});

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ function createLogger(options = {}) {
6969
return emptyLogger();
7070
}
7171

72-
const loggerOptions = Object.assign({}, defaults, options):
72+
const loggerOptions = Object.assign({}, defaults, options);
7373

7474
// Return if 'console' object is not defined
7575
if (noLogger(loggerOptions)) return emptyLogger();
7676

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

8181
const started = timer.now();
8282
const startedTime = new Date();

0 commit comments

Comments
 (0)