Arif
Arif

Reputation: 6478

ReactJS unit test says TypeError: Cannot read property 'apply' of undefined

My project works fine, but when I type the command yarn test to run the test, then it shows this error:

enter image description here
I think this error happened because of REDUX_DEVTOOLS in store, here is my store setup with REDUX_DEVTOOLS_EXTENSION:

const persistConfig = {
    key: 'root',
    storage,
};

const persistedReducer = persistReducer(persistConfig, UserReducer);

const reducers = combineReducers({
    persistedStore: persistedReducer,
    aoiStore: AoiReducer,
    aoi: AoiEventReducer,
    opticalDataStore: OpticalDataReducer,
    loaderStore: LoaderReducer,
});

export const store = createStore(
    reducers,
    compose(
        applyMiddleware(thunk),
        (window as any).__REDUX_DEVTOOLS_EXTENSION__ &&
            (window as any).__REDUX_DEVTOOLS_EXTENSION__(),
    ),
);

export const persistor = persistStore(store);

For your info, if I remove this line from the store then it works fine:

(window as any).__REDUX_DEVTOOLS_EXTENSION__ &&
    (window as any).__REDUX_DEVTOOLS_EXTENSION__()

Can anyone tell me where I made the mistake?

Upvotes: 0

Views: 372

Answers (1)

Vishal Sharma
Vishal Sharma

Reputation: 336

You should never import the actual store file in your test. redux-mock-store is a wonderful package which gives you the capability to mock the store according to you test file requirement.

Upvotes: 1

Related Questions