My jest config
clearMocks: true,
rootDir: '../../',
cacheDirectory: 'cache',
testEnvironment: 'jsdom',
modulePaths: [
'<rootDir>'
],
setupFilesAfterEnv: [
'<rootDir>/config/jest/setup.ts'
],
moduleDirectories: [
'node_modules', 'src'
],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|svg)$': '<rootDir>/config/jest/mocks/file.js',
'\\.s?css$': 'identity-obj-proxy'
},
moduleFileExtensions: [
'js', 'mjs', 'cjs', 'jsx', 'ts', 'tsx', 'json', 'node'
],
roots: [ '<rootDir>/src' ],
transformIgnorePatterns: [
'/node_modules/',
'\\.pnp\\.[^\\/]+$',
'/vendor/'
],
globals: {
__IS_DEV__: false
},
testMatch: [
'**/__tests__/**/*unit.[jt]s?(x)',
],
I import import { counterReducer, CounterStateSchema } from 'entities/Counter';
All working fine when I rename the directory entities to any other directory. For Example ['aaaa', 'bbbb', 'entity'] and others.
PASS src/aaaa/Counter/ui/__tests__/Counter.unit.tsx
Counter
✓ test render Counter (106 ms)
But the directory named is entities test fails with error:
FAIL src/entities/Counter/ui/__tests__/Counter.unit.tsx
● Test suite failed to run
Cannot find module 'entities/Counter' from 'src/app/config/redux/index.ts'
All other import working fine in my project and I have no idea, what it could be.
All other in my project working fine. Webpack, Storybook and so on.
I can't change the directory "entities" to other because I use Feature-Sliced Design. According to this methodology there should be this folder.
If I use relative path, it's work
-----script app/config/redux/index.ts------
import { counterReducer, CounterStateSchema } from '../../../entities/Counter';
----test result---
PASS src/entities/Counter/ui/__tests__/Counter.unit.tsx
Counter
✓ test render Counter (102 ms)
I found a bug in the jest-environment-jsdom package. Reported the bug to the jest team. Link to the bug here