6
6
allowDuplicates : true
7
7
} ) . install ( ) ;
8
8
9
- const reducer = ( previousState = { value : 0 } , action ) => {
9
+ const defaultState = { value : 0 } ;
10
+ const context = {
11
+ initialState : defaultState
12
+ } ;
13
+
14
+ const reducer = ( previousState = context . initialState , action ) => {
10
15
switch ( action . type ) {
11
16
case "THROW" :
12
17
// Raven does not seem to be able to capture global exceptions in Jest tests.
@@ -23,11 +28,10 @@ const reducer = (previousState = { value: 0 }, action) => {
23
28
}
24
29
} ;
25
30
26
- const context = { } ;
27
-
28
31
describe ( "raven-for-redux" , ( ) => {
29
32
beforeEach ( ( ) => {
30
33
context . mockTransport = jest . fn ( ) ;
34
+ context . initialState = defaultState ;
31
35
Raven . setTransport ( context . mockTransport ) ;
32
36
Raven . setDataCallback ( undefined ) ;
33
37
Raven . setBreadcrumbCallback ( undefined ) ;
@@ -186,6 +190,93 @@ describe("raven-for-redux", () => {
186
190
userData
187
191
) ;
188
192
} ) ;
193
+ describe ( "with redux-undo history as top-level state" , ( ) => {
194
+ beforeEach ( ( ) => {
195
+ context . initialState = {
196
+ past : [ { value : 2 } , { value : 1 } ] ,
197
+ present : { value : 0 } ,
198
+ future : [ ] ,
199
+ index : 2 ,
200
+ limit : 2
201
+ } ;
202
+ context . store = createStore (
203
+ reducer ,
204
+ applyMiddleware ( context . middleware )
205
+ ) ;
206
+ } ) ;
207
+ it ( "replaces the past and future arrays in the state" , ( ) => {
208
+ expect ( ( ) => {
209
+ context . store . dispatch ( { type : "THROW" } ) ;
210
+ } ) . toThrow ( ) ;
211
+
212
+ expect ( context . mockTransport ) . toHaveBeenCalledTimes ( 1 ) ;
213
+ const { extra } = context . mockTransport . mock . calls [ 0 ] [ 0 ] . data ;
214
+ expect ( extra . state ) . toEqual ( {
215
+ past : "redux-undo history was automatically removed. (Entries: 2)" ,
216
+ present : { value : 0 } ,
217
+ future : "redux-undo history was automatically removed. (Entries: 0)" ,
218
+ index : 2 ,
219
+ limit : 2
220
+ } ) ;
221
+ } ) ;
222
+ } ) ;
223
+ describe ( "with redux-undo history as nested stores" , ( ) => {
224
+ beforeEach ( ( ) => {
225
+ context . initialState = {
226
+ fooStore : {
227
+ past : [ { value : 2 } , { value : 1 } ] ,
228
+ present : { value : 0 } ,
229
+ future : [ ] ,
230
+ index : 2 ,
231
+ limit : 2
232
+ } ,
233
+ barStore : {
234
+ value : 2
235
+ }
236
+ } ;
237
+ context . store = createStore (
238
+ reducer ,
239
+ applyMiddleware ( context . middleware )
240
+ ) ;
241
+ } ) ;
242
+ it ( "replaces past and future arrays in any nested stores that use redux-undo" , ( ) => {
243
+ expect ( ( ) => {
244
+ context . store . dispatch ( { type : "THROW" } ) ;
245
+ } ) . toThrow ( ) ;
246
+ expect ( context . mockTransport ) . toHaveBeenCalledTimes ( 1 ) ;
247
+ const { extra } = context . mockTransport . mock . calls [ 0 ] [ 0 ] . data ;
248
+ expect ( extra . state ) . toEqual ( {
249
+ fooStore : {
250
+ past : "redux-undo history was automatically removed. (Entries: 2)" ,
251
+ present : { value : 0 } ,
252
+ future :
253
+ "redux-undo history was automatically removed. (Entries: 0)" ,
254
+ index : 2 ,
255
+ limit : 2
256
+ } ,
257
+ barStore : {
258
+ value : 2
259
+ }
260
+ } ) ;
261
+ } ) ;
262
+ } ) ;
263
+ describe ( "with state that is not an object" , ( ) => {
264
+ beforeEach ( ( ) => {
265
+ context . initialState = 42 ;
266
+ context . store = createStore (
267
+ reducer ,
268
+ applyMiddleware ( context . middleware )
269
+ ) ;
270
+ } ) ;
271
+ it ( "does not affect the state" , ( ) => {
272
+ expect ( ( ) => {
273
+ context . store . dispatch ( { type : "THROW" } ) ;
274
+ } ) . toThrow ( ) ;
275
+ expect ( context . mockTransport ) . toHaveBeenCalledTimes ( 1 ) ;
276
+ const { extra } = context . mockTransport . mock . calls [ 0 ] [ 0 ] . data ;
277
+ expect ( extra . state ) . toEqual ( 42 ) ;
278
+ } ) ;
279
+ } ) ;
189
280
} ) ;
190
281
describe ( "with all the options enabled" , ( ) => {
191
282
beforeEach ( ( ) => {
0 commit comments