@@ -22,27 +22,54 @@ context('default logger', () => {
2222} ) ;
2323
2424context ( '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} ) ;
0 commit comments