@@ -2,10 +2,40 @@ import { expect } from 'chai';
22
33import { repeat } from 'helpers' ;
44
5+ import { applyMiddleware , createStore } from 'redux' ;
6+
7+ import sinon from 'sinon' ;
8+
9+ import createLogger from '../src' ;
10+
511context ( `Helpers` , ( ) => {
612 describe ( `'repeat'` , ( ) => {
713 it ( `should repeat a string the number of indicated times` , ( ) => {
814 expect ( repeat ( `teacher` , 3 ) ) . to . equal ( `teacherteacherteacher` ) ;
915 } ) ;
1016 } ) ;
1117} ) ;
18+
19+ context ( 'createLogger' , ( ) => {
20+ describe ( 'initialization' , ( ) => {
21+ beforeEach ( ( ) => {
22+ sinon . spy ( console , 'error' ) ;
23+ } ) ;
24+
25+ afterEach ( ( ) => {
26+ console . error . restore ( ) ;
27+ } ) ;
28+
29+ it ( 'should log an error if the function is passed to applyMiddleware' , ( ) => {
30+ const store = createStore ( ( ) => ( { } ) , applyMiddleware ( createLogger ) ) ;
31+ store . dispatch ( { type : 'foo' } ) ;
32+ sinon . assert . calledOnce ( console . error ) ;
33+ } ) ;
34+
35+ it ( 'should not log an error if the correct function is passed' , ( ) => {
36+ const store = createStore ( ( ) => ( { } ) , applyMiddleware ( createLogger ( ) ) ) ;
37+ store . dispatch ( { type : 'foo' } ) ;
38+ sinon . assert . notCalled ( console . error ) ;
39+ } ) ;
40+ } ) ;
41+ } ) ;
0 commit comments