I followed the guide as per Jest configuration for Webpack built React applications & have resolved quite a few errors I had previously. However, this following error has be puzzled. Error:
Cannot find module 'expect' from 'jest_expect.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:194:17)
Here is my package.json
"devDependencies / dependencies" :
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.1",
"babel-jest": "^22.2.2",
"babel-loader": "^7.1.2",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"jest": "^22.3.0",
"webpack": "^3.11.0",
"webpack-dev-server": "^2.11.1"
...
"identity-obj-proxy": "^3.0.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-form": "^7.3.0",
"redux-thunk": "^2.2.0",
"webpack-merge": "^4.1.1"
},
"jest": {
"verbose": true,
"moduleDirectories": ["mode_modules"],
"moduleFileExtensions": ["js", "jsx"],
"moduleNameMapper": {
"app(.*)$": "<rootDir>/apps$1",
"appAthenaTrader(.*)$": "<rootDir>/apps/athenaTrader$1",
"common(.*)$": "<rootDir>/src/modules/Common$1",
"modules(.*)$": "<rootDir>/src/modules$1",
"src(.*)$": "<rootDir>/src$1"
},
"modulePaths": ["src", "apps"]
}
My webpack.config.js :
const PATHS = {
app: path.join(__dirname, 'apps'),
src: path.join(__dirname, 'src'),
modules: path.join(__dirname, 'src/modules'),
common: path.join(__dirname, 'src/modules/Common'),
styles: path.join(__dirname, 'src/styles')
};
const common = {
output: {
path: PATHS.build,
publicPath: '/',
filename: 'bundle.js'
},
resolve: {
alias: {
app: PATHS.app,
Common: PATHS.common,
modules: PATHS.modules,
src: PATHS.src,
styles: PATHS.styles
},
extensions: ['.js', '.jsx', '.json']
},
module: {
rules: [
{
test: /\.jsx?$/,
include: [PATHS.app, PATHS.src],
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true
}
}
]
},
...
The test I have written is:
import { Map as iMap } from 'immutable';
import * as actions from '../actionTypes';
import * as actionTypes from '../actions';
describe('Testing of User actions...', () => {
it('should create an action for sendingUserAuthRequest', () => {
const action = {
type: actionTypes.SEND_AUTH_REQUEST,
payload: iMap({
isFetching: true,
isAuthenticated: false
})
};
expect(actions.sendUserAuthRequest()).toEqual(action);
});
});
Some of the solutions I have read & tried include this link to regex moduleNameMapper.
To reiterate, whenever I run the tests, I get the
Cannot find module 'expect' from 'jest_expect.js'