@@ -22,27 +22,54 @@ context('default logger', () => {
22
22
} ) ;
23
23
24
24
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' , ( ) => {
26
38
beforeEach ( ( ) => {
27
- sinon . spy ( console , 'error' ) ;
39
+ store = createStore ( ( ) => ( { } ) , applyMiddleware ( createLogger ) ) ;
28
40
} ) ;
29
41
30
- afterEach ( ( ) => {
31
- console . error . restore ( ) ;
42
+ it ( 'should log error' , ( ) => {
43
+ sinon . assert . calledOnce ( console . error ) ;
32
44
} ) ;
33
45
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
+ } ) ;
36
57
58
+ it ( 'should create an empty middleware' , ( ) => {
37
59
store . dispatch ( { type : 'foo' } ) ;
38
- sinon . assert . calledOnce ( console . error ) ;
60
+ sinon . assert . notCalled ( console . log ) ;
39
61
} ) ;
62
+ } ) ;
40
63
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
+ } ) ;
43
69
70
+ it ( 'should not log' , ( ) => {
44
71
store . dispatch ( { type : 'foo' } ) ;
45
- sinon . assert . notCalled ( console . error ) ;
72
+ sinon . assert . notCalled ( console . log ) ;
46
73
} ) ;
47
74
} ) ;
48
75
} ) ;
0 commit comments