@@ -33,7 +33,8 @@ describe('Reactor', () => {
3333 expect ( getOption ( reactor . reactorState , 'logDispatches' ) ) . toBe ( true )
3434 expect ( getOption ( reactor . reactorState , 'logAppState' ) ) . toBe ( false )
3535 expect ( getOption ( reactor . reactorState , 'logDirtyStores' ) ) . toBe ( false )
36- expect ( getOption ( reactor . reactorState , 'throwOnUndefinedDispatch' ) ) . toBe ( false )
36+ expect ( getOption ( reactor . reactorState , 'throwOnUndefinedActionType' ) ) . toBe ( false )
37+ expect ( getOption ( reactor . reactorState , 'throwOnUndefinedStoreReturnValue' ) ) . toBe ( false )
3738 expect ( getOption ( reactor . reactorState , 'throwOnNonImmutableStore' ) ) . toBe ( false )
3839 expect ( getOption ( reactor . reactorState , 'throwOnDispatchInDispatch' ) ) . toBe ( false )
3940 } )
@@ -48,12 +49,253 @@ describe('Reactor', () => {
4849 expect ( getOption ( reactor . reactorState , 'logDispatches' ) ) . toBe ( false )
4950 expect ( getOption ( reactor . reactorState , 'logAppState' ) ) . toBe ( true )
5051 expect ( getOption ( reactor . reactorState , 'logDirtyStores' ) ) . toBe ( true )
51- expect ( getOption ( reactor . reactorState , 'throwOnUndefinedDispatch' ) ) . toBe ( true )
52+ expect ( getOption ( reactor . reactorState , 'throwOnUndefinedActionType' ) ) . toBe ( true )
53+ expect ( getOption ( reactor . reactorState , 'throwOnUndefinedStoreReturnValue' ) ) . toBe ( true )
5254 expect ( getOption ( reactor . reactorState , 'throwOnNonImmutableStore' ) ) . toBe ( true )
5355 expect ( getOption ( reactor . reactorState , 'throwOnDispatchInDispatch' ) ) . toBe ( false )
5456 } )
5557 } )
5658
59+ describe ( 'options' , ( ) => {
60+ describe ( 'throwOnUndefinedActionType' , ( ) => {
61+ it ( 'should NOT throw when `false`' , ( ) => {
62+ var reactor = new Reactor ( {
63+ options : {
64+ throwOnUndefinedActionType : false ,
65+ } ,
66+ } )
67+
68+ expect ( ( ) => {
69+ reactor . dispatch ( undefined )
70+ } ) . not . toThrow ( )
71+ } )
72+
73+ it ( 'should throw when `true`' , ( ) => {
74+ var reactor = new Reactor ( {
75+ options : {
76+ throwOnUndefinedActionType : true ,
77+ } ,
78+ } )
79+
80+ expect ( ( ) => {
81+ reactor . dispatch ( undefined )
82+ } ) . toThrow ( )
83+ } )
84+ } )
85+
86+ describe ( 'throwOnUndefinedStoreReturnValue' , ( ) => {
87+ it ( 'should NOT throw during `registerStores`, `dispatch` or `reset` when `false`' , ( ) => {
88+ var reactor = new Reactor ( {
89+ options : {
90+ throwOnUndefinedStoreReturnValue : false ,
91+ } ,
92+ } )
93+
94+ expect ( ( ) => {
95+ reactor . registerStores ( {
96+ store : Store ( {
97+ getInitialState ( ) {
98+ return undefined
99+ } ,
100+ initialize ( ) {
101+ this . on ( 'action' , ( ) => undefined )
102+ } ,
103+ } )
104+ } )
105+ reactor . dispatch ( 'action' )
106+ reactor . reset ( )
107+ } ) . not . toThrow ( )
108+ } )
109+
110+ it ( 'should throw during `registerStores` when `true`' , ( ) => {
111+ var reactor = new Reactor ( {
112+ options : {
113+ throwOnUndefinedStoreReturnValue : true ,
114+ } ,
115+ } )
116+
117+ expect ( ( ) => {
118+ reactor . registerStores ( {
119+ store : Store ( {
120+ getInitialState ( ) {
121+ return undefined
122+ } ,
123+ initialize ( ) {
124+ this . on ( 'action' , ( ) => undefined )
125+ } ,
126+ } )
127+ } )
128+ } ) . toThrow ( )
129+ } )
130+
131+ it ( 'should throw during `dispatch` when `true`' , ( ) => {
132+ var reactor = new Reactor ( {
133+ options : {
134+ throwOnUndefinedStoreReturnValue : true ,
135+ } ,
136+ } )
137+
138+ expect ( ( ) => {
139+ reactor . registerStores ( {
140+ store : Store ( {
141+ getInitialState ( ) {
142+ return undefined
143+ } ,
144+ initialize ( ) {
145+ this . on ( 'action' , ( ) => undefined )
146+ } ,
147+ } )
148+ } )
149+ } ) . toThrow ( )
150+ } )
151+
152+ it ( 'should throw during `reset` when `true`' , ( ) => {
153+ var reactor = new Reactor ( {
154+ options : {
155+ throwOnUndefinedStoreReturnValue : true ,
156+ } ,
157+ } )
158+
159+ expect ( ( ) => {
160+ reactor . registerStores ( {
161+ store : Store ( {
162+ getInitialState ( ) {
163+ return 1
164+ } ,
165+ handleReset ( ) {
166+ return undefined
167+ }
168+ } )
169+ } )
170+ reactor . reset ( )
171+ } ) . toThrow ( )
172+ } )
173+ } )
174+
175+ describe ( 'throwOnNonImmutableStore' , ( ) => {
176+ it ( 'should NOT throw during `registerStores` or `reset` when `false`' , ( ) => {
177+ var reactor = new Reactor ( {
178+ options : {
179+ throwOnNonImmutableStore : false ,
180+ } ,
181+ } )
182+
183+ expect ( ( ) => {
184+ reactor . registerStores ( {
185+ store : Store ( {
186+ getInitialState ( ) {
187+ return { foo : 'bar' }
188+ } ,
189+ handleReset ( ) {
190+ return { foo : 'baz' }
191+ } ,
192+ } )
193+ } )
194+ reactor . reset ( )
195+ } ) . not . toThrow ( )
196+ } )
197+
198+ it ( 'should throw during `registerStores` when `true`' , ( ) => {
199+ var reactor = new Reactor ( {
200+ options : {
201+ throwOnNonImmutableStore : true ,
202+ } ,
203+ } )
204+
205+ expect ( ( ) => {
206+ reactor . registerStores ( {
207+ store : Store ( {
208+ getInitialState ( ) {
209+ return { foo : 'bar' }
210+ } ,
211+ } )
212+ } )
213+ } ) . toThrow ( )
214+ } )
215+
216+ it ( 'should throw during `reset` when `true`' , ( ) => {
217+ var reactor = new Reactor ( {
218+ options : {
219+ throwOnNonImmutableStore : true ,
220+ } ,
221+ } )
222+
223+ expect ( ( ) => {
224+ reactor . registerStores ( {
225+ store : Store ( {
226+ getInitialState ( ) {
227+ return 123
228+ } ,
229+ handleReset ( ) {
230+ return { foo : 'baz' }
231+ } ,
232+ } )
233+ } )
234+ reactor . reset ( )
235+ } ) . toThrow ( )
236+ } )
237+ } )
238+
239+ describe ( 'throwOnDispatchInDispatch' , ( ) => {
240+ it ( 'should NOT throw when `false`' , ( ) => {
241+ var reactor = new Reactor ( {
242+ options : {
243+ throwOnDispatchInDispatch : false ,
244+ } ,
245+ } )
246+
247+ expect ( ( ) => {
248+ reactor . registerStores ( {
249+ count : Store ( {
250+ getInitialState ( ) {
251+ return 1
252+ } ,
253+ initialize ( ) {
254+ this . on ( 'increment' , curr => curr + 1 )
255+ }
256+ } )
257+ } )
258+
259+ reactor . observe ( [ 'count' ] , ( val ) => {
260+ if ( val % 2 === 0 ) {
261+ reactor . dispatch ( 'increment' )
262+ }
263+ } )
264+ reactor . dispatch ( 'increment' )
265+ expect ( reactor . evaluate ( [ 'count' ] ) ) . toBe ( 3 )
266+ } ) . not . toThrow ( )
267+ } )
268+
269+ it ( 'should throw when `true`' , ( ) => {
270+ var reactor = new Reactor ( {
271+ options : {
272+ throwOnDispatchInDispatch : true ,
273+ } ,
274+ } )
275+
276+ expect ( ( ) => {
277+ reactor . registerStores ( {
278+ count : Store ( {
279+ getInitialState ( ) {
280+ return 1
281+ } ,
282+ initialize ( ) {
283+ this . on ( 'increment' , curr => curr + 1 )
284+ }
285+ } )
286+ } )
287+
288+ reactor . observe ( [ 'count' ] , ( val ) => {
289+ if ( val % 2 === 0 ) {
290+ reactor . dispatch ( 'increment' )
291+ }
292+ } )
293+ reactor . dispatch ( 'increment' )
294+ } ) . toThrow ( )
295+ } )
296+ } )
297+ } )
298+
57299 describe ( 'Reactor with no initial state' , ( ) => {
58300 var checkoutActions
59301 var reactor
0 commit comments