@@ -3,7 +3,7 @@ import { Reactor, Store } from '../src/main'
3
3
import { getOption } from '../src/reactor/fns'
4
4
import { toImmutable } from '../src/immutable-helpers'
5
5
import { PROD_OPTIONS , DEBUG_OPTIONS } from '../src/reactor/records'
6
- import logging from '../src/logging'
6
+ import { NoopLogger , ConsoleGroupLogger } from '../src/logging'
7
7
8
8
describe ( 'Reactor' , ( ) => {
9
9
it ( 'should construct without \'new\'' , ( ) => {
@@ -54,6 +54,82 @@ describe('Reactor', () => {
54
54
expect ( getOption ( reactor . reactorState , 'throwOnNonImmutableStore' ) ) . toBe ( true )
55
55
expect ( getOption ( reactor . reactorState , 'throwOnDispatchInDispatch' ) ) . toBe ( false )
56
56
} )
57
+
58
+ describe ( 'custom logging' , ( ) => {
59
+ var handler
60
+
61
+ beforeEach ( ( ) => {
62
+ handler = {
63
+ dispatchStart ( ) { } ,
64
+ dispatchError ( ) { } ,
65
+ dispatchEnd ( ) { } ,
66
+ }
67
+ spyOn ( handler , 'dispatchStart' )
68
+ spyOn ( handler , 'dispatchError' )
69
+ spyOn ( handler , 'dispatchEnd' )
70
+
71
+ spyOn ( NoopLogger , 'dispatchError' )
72
+ } )
73
+
74
+ afterEach ( ( ) => {
75
+ handler = null
76
+ } )
77
+
78
+ it ( 'should use dispatchStart on the provided logging handler if defined' , ( ) => {
79
+ var reactor = new Reactor ( {
80
+ debug : true ,
81
+ logger : handler ,
82
+ } )
83
+
84
+ reactor . dispatch ( 'setTax' , 5 )
85
+
86
+ expect ( handler . dispatchStart ) . toHaveBeenCalled ( )
87
+ } )
88
+ it ( 'should use dispatchEnd on the provided logging handler if defined' , ( ) => {
89
+ var reactor = new Reactor ( {
90
+ debug : true ,
91
+ logger : handler ,
92
+ } )
93
+
94
+ reactor . dispatch ( 'setTax' , 5 )
95
+
96
+ expect ( handler . dispatchEnd ) . toHaveBeenCalled ( )
97
+ } )
98
+ it ( 'should use dispatchError on the provided logging handler if defined' , ( ) => {
99
+ var reactor = new Reactor ( {
100
+ debug : true ,
101
+ logger : handler ,
102
+ options : {
103
+ throwOnUndefinedActionType : false ,
104
+ } ,
105
+ } )
106
+
107
+ try {
108
+ reactor . dispatch ( undefined )
109
+ } catch ( e ) {
110
+ expect ( handler . dispatchError ) . toHaveBeenCalled ( )
111
+ }
112
+ } )
113
+ it ( 'should use the NoopLogger implementation when a logging function is not defined on the custom implementation' , ( ) => {
114
+ var reactor = new Reactor ( {
115
+ debug : true ,
116
+ logger : {
117
+ dispatchStart ( ) { } ,
118
+ dispatchEnd ( ) { } ,
119
+ } ,
120
+ options : {
121
+ throwOnUndefinedActionType : false ,
122
+ } ,
123
+ } )
124
+
125
+ try {
126
+ reactor . dispatch ( undefined )
127
+ } catch ( e ) {
128
+ expect ( NoopLogger . dispatchError ) . toHaveBeenCalled ( )
129
+ }
130
+ } )
131
+
132
+ } )
57
133
} )
58
134
59
135
describe ( 'options' , ( ) => {
@@ -1098,7 +1174,7 @@ describe('Reactor', () => {
1098
1174
var reactor
1099
1175
1100
1176
beforeEach ( ( ) => {
1101
- spyOn ( logging , 'dispatchError' )
1177
+ spyOn ( ConsoleGroupLogger , 'dispatchError' )
1102
1178
var throwingStore = new Store ( {
1103
1179
getInitialState ( ) {
1104
1180
return 1
@@ -1124,7 +1200,7 @@ describe('Reactor', () => {
1124
1200
expect ( function ( ) {
1125
1201
reactor . dispatch ( 'set' , 'foo' )
1126
1202
} ) . toThrow ( new Error ( 'Error during action handling' ) )
1127
- expect ( logging . dispatchError ) . toHaveBeenCalledWith ( reactor . reactorState , 'Error during action handling' )
1203
+ expect ( ConsoleGroupLogger . dispatchError ) . toHaveBeenCalledWith ( reactor . reactorState , 'Error during action handling' )
1128
1204
} )
1129
1205
} )
1130
1206
0 commit comments