TypeError: Cannot read property during test run on jest

Viewed 33

Help me figure out with Jest what I'm doing wrong or what I'm not doing. I can't understand why Jest doesn't see the imported redux module I'm trying to test an application on nodejs

Written test:

// userRequest.test.js    
import { setUserRequest } from './../modules/userRequest.js'
    
test('Save user request', async () => {
   expect(await setUserRequest({dealid: '123'}, 1, 'login', 'dfd', 'mytype')).toBeTruthy()
})

imports in the file userRequest.js

import { logger, msgb } from './logger.js';
import stor from './store/index.js';
import {printStackTrace} from "./functions.js";

file /store/index.js

import reduxx from 'redux';
import { cacheStore } from "./cacheStore.js";
const cacheDatafn = () => {
  const redux = reduxx;
  return redux.createStore(cacheStore);
}

The test fails with an error: FAIL tests/userRequest.test.js ā— Test suite failed to run

TypeError: Cannot read property 'createStore' of undefined

  16 | const cacheDatafn = () => {
  17 |   const redux = reduxx;
> 18 |   return redux.createStore(cacheStore);
     |                ^
  19 | }
  20 |
  21 | const constDatafn = () => {

  at cacheDatafn (modules/store/index.js:18:16)
  at Object.<anonymous> (modules/store/index.js:61:19)

How do I get Jest to see the redux module?

Versions - nodejs: 14.17.4, jest: 27.5.1

P.S. This const redux = reduxx; appeared as a result of various experiments, initially this line was not in the function, it was just return redux.createStore(CacheStore)

0 Answers
Related