@@ -330,6 +330,61 @@ describe('serializableStateInvariantMiddleware', () => {
330330 expect ( numTimesCalled ) . toBeGreaterThan ( 0 )
331331 } )
332332
333+ describe ( 'ignored action paths' , ( ) => {
334+ function reducer ( ) {
335+ return 0
336+ }
337+ const nonSerializableValue = new Map ( )
338+
339+ it ( 'default value: meta.arg' , ( ) => {
340+ configureStore ( {
341+ reducer,
342+ middleware : [ createSerializableStateInvariantMiddleware ( ) ]
343+ } ) . dispatch ( { type : 'test' , meta : { arg : nonSerializableValue } } )
344+
345+ expect ( getLog ( ) . log ) . toMatchInlineSnapshot ( `""` )
346+ } )
347+
348+ it ( 'default value can be overridden' , ( ) => {
349+ configureStore ( {
350+ reducer,
351+ middleware : [
352+ createSerializableStateInvariantMiddleware ( {
353+ ignoredActionPaths : [ ]
354+ } )
355+ ]
356+ } ) . dispatch ( { type : 'test' , meta : { arg : nonSerializableValue } } )
357+
358+ expect ( getLog ( ) . log ) . toMatchInlineSnapshot ( `
359+ "A non-serializable value was detected in an action, in the path: \`meta.arg\`. Value: Map {}
360+ Take a look at the logic that dispatched this action: Object {
361+ \\"meta\\": Object {
362+ \\"arg\\": Map {},
363+ },
364+ \\"type\\": \\"test\\",
365+ }
366+ (See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)"
367+ ` )
368+ } )
369+
370+ it ( 'can specify (multiple) different values' , ( ) => {
371+ configureStore ( {
372+ reducer,
373+ middleware : [
374+ createSerializableStateInvariantMiddleware ( {
375+ ignoredActionPaths : [ 'payload' , 'meta.arg' ]
376+ } )
377+ ]
378+ } ) . dispatch ( {
379+ type : 'test' ,
380+ payload : { arg : nonSerializableValue } ,
381+ meta : { arg : nonSerializableValue }
382+ } )
383+
384+ expect ( getLog ( ) . log ) . toMatchInlineSnapshot ( `""` )
385+ } )
386+ } )
387+
333388 it ( 'should not check serializability for ignored slice names' , ( ) => {
334389 const ACTION_TYPE = 'TEST_ACTION'
335390
@@ -386,29 +441,6 @@ describe('serializableStateInvariantMiddleware', () => {
386441 ` )
387442 } )
388443
389- it ( 'should not check serializability for meta.args by default' , ( ) => {
390- const badValue = new Map ( )
391-
392- const reducer : Reducer = ( state = 42 , action ) => {
393- return state
394- }
395-
396- const serializableStateInvariantMiddleware = createSerializableStateInvariantMiddleware ( )
397-
398- const store = configureStore ( {
399- reducer : {
400- testSlice : reducer
401- } ,
402- middleware : [ serializableStateInvariantMiddleware ]
403- } )
404-
405- store . dispatch ( { type : 'testAction' , meta : { args : { badValue } } } )
406-
407- const { log } = getLog ( )
408- expect ( log ) . toBe ( '' )
409- const q = 42
410- } )
411-
412444 it ( 'Should print a warning if execution takes too long' , ( ) => {
413445 const reducer : Reducer = ( state = 42 , action ) => {
414446 return state
0 commit comments