Search code examples
reactjsreact-reduxjestjsredux-toolkit

How to disable redux-toolkit's "non-serialiable value" warning for tests?


I'm passing/injecting React components with Redux, utilizing redux-toolkit. Since they're not serializable, I've successfully disabled the check with that configuration:

const store = configureStore({
  reducer: {
    ...
  },
  devTools: process.env.NODE_ENV === 'development',
  middleware: (getDefaultMiddleware) => {
    console.log('IN MIDDLEWARE'); // gets logged in tests, so jests gets to this point
    return getDefaultMiddleware({
      serializableCheck: false, // works in the app, but doesn't in tests - I still see the error log there
    });
  },
});

This works fine in the application, but for some reason doesn't not help to suppress the error A non-serializable value was detected in an action getting logged in jest tests. I don't understand why it's still there and cluttering my test logs.


Solution

  • It appears you are using a custom render function for your tests. The store configuration there needs to be exactly the same as above.