redux/toolkit + Reactotron leads to jest error "TypeError: _reactotronConfig.default.createEnhancer is not a function"

176 Views Asked by At

For quite some time, I've been trying to configure Reactotron and Redux Toolkit to avoid this annoying jest error: "TypeError: _reactotronConfig.default.createEnhancer is not a function," but without success. Reactotron is working properly; I can see the actions in the Reactotron desktop app, and so on. However, I can't get rid of this error. All suggestions are welcome. I have tried everything I found on the internet.Here is my setup:

reactotronConfig:

import Reactotron, { trackGlobalErrors, asyncStorage } from 'reactotron-react-native';
import { reactotronRedux } from 'reactotron-redux';
import { name as appName } from './app.json';

Reactotron.configure({
  name: appName,
})
  .use(asyncStorage())
  .use(trackGlobalErrors())
  .useReactNative({
    storybook: true,
  })
  .use(reactotronRedux())
  .connect();
// .clear();

console.tron = Reactotron;

export default Reactotron;

reactotron-react-native.js (reactotron mock file):

export const Reactotron = {
  configure: () => Reactotron,
  useReactNative: () => Reactotron,
  asyncStorage: () => Reactotron,
  trackGlobalErrors: () => Reactotron,
  createEnhancer: () => Reactotron,
  use: () => Reactotron,
  connect: () => Reactotron,
  clear: () => Reactotron,
};

module.exports = Reactotron;

store:

import { configureStore, ThunkAction, Action } from '@reduxjs/toolkit';
import rootReducer from './reducers';
import Reactotron from '../../reactotronConfig';

export const store = configureStore({
  reducer: rootReducer,
  middleware: [],
  enhancers: [(Reactotron as any).createEnhancer!()],
});

The ERROR: enter image description here

1

There are 1 best solutions below

0
On

The problem was due to how i mocked createEnhancer function. It should be:

createEnhancer: () => jest.fn  <-- without the execution "()"