I am stuck on this error, can anyone help?
โ Test suite failed to run
Configuration error:
Could not locate module ./assets/images/navbar/add.png mapped as:
RelativeImageStub.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^[@.\/a-zA-Z0-9$_-]+\.(png|gif)$/": "RelativeImageStub"
},
"resolver": null
}
> 1 | exports.addDark = require('./assets/images/navbar/add.png');
| ^
2 | exports.addFirst = require('./assets/images/add_home_tile_empty.png');
3 | exports.addIcon = require('./assets/images/add_white.png');
4 | exports.addTileIcon = require('./assets/images/add_tile.png');
at createNoMappedModuleFoundError (node_modules/jest-resolve/build/index.js:471:17)
at Object.require (ReactApp/images.js:1:19)
jest.config.js:
module.exports = {
preset: 'react-native',
testEnvironment: 'jsdom',
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
'.(ts|tsx)': 'ts-jest'
},
testPathIgnorePatterns: [
'\\.snap$',
'<rootDir>/node_modules/',
'<rootDir>/build',
'<rootDir>/ReactApp/util.ts'
],
transformIgnorePatterns: [
'node_modules/(?!react-native|@react-native-community|lottie-react-native|@mitel-internal|@expo|react-clone-referenced-element)'
],
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$',
moduleFileExtensions: ['ts', 'tsx', 'js'],
modulePathIgnorePatterns: [
'<rootDir>/node_modules/react-native/node_modules/fbjs/lib/__mocks__/ErrorUtils.js'
],
globals: {
'ts-jest': {
babelConfig: true,
diagnostics: false
}
},
moduleNameMapper: {
'^image![a-zA-Z0-9$_-]+$': 'GlobalImageStub',
'^[@./a-zA-Z0-9$_-]+\\.(png|gif)$': 'RelativeImageStub'
},
coverageDirectory: '<rootDir>/build/coverage/',
coverageReporters: ['json', 'lcov', 'text-summary'],
collectCoverageFrom: [
'**/*.{js,jsx,tsx}',
'!**/node_modules/**',
'!**/build/**',
'!**/android/**',
'!**/ios/**'
],
setupFiles: ['<rootDir>/ReactApp/JestConfig.js'],
cacheDirectory: '.jest/cache'
};
package.json:
"devDependencies": {
"@babel/core": "^7.4.3",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/runtime": "^7.4.3",
"@types/jest": "^24.0.12",
"@types/lodash": "^4.14.111",
"@types/node": "^10.11.1",
"@types/react": "^16.8.17",
"@types/react-native": "^0.57.6",
"@types/react-redux": "^4.4.46",
"@types/react-test-renderer": "^16.0.2",
"@types/redux": "^3.6.0",
"@types/redux-logger": "^3.0.5",
"@types/redux-promise": "^0.5.28",
"@types/redux-thunk": "^2.1.0",
"@types/whatwg-url": "^6.4.0",
"babel-bridge": "^1.12.11",
"babel-jest": "24.8.0",
"husky": "^0.14.3",
"jest": "^24.7.1",
"lint-staged": "^7.2.0",
"metro-react-native-babel-preset": "^0.53.1",
"nock": "^9.0.14",
"prettier": "1.13.7",
"react-native-debugger-open": "^0.3.22",
"react-native-sm-transformer": "^1.0.3",
"react-native-typescript-transformer": "^1.2.10",
"react-test-context-provider": "^2.2.0",
"react-test-renderer": "16.8.3",
"redux-devtools-extension": "^2.13.2",
"redux-mock-store": "^1.2.3",
"regenerator-runtime": "^0.12.1",
"rn-test-exception-handler": "^1.3.2",
"ts-jest": "^24.0.2",
"typescript": "3.7.5"
}
Fixed by changing to this in jest.config.js:
moduleNameMapper: {
'^[@./a-zA-Z0-9$_-]+\\.(png|gif)$': '<rootDir>/node_modules/react-native/Libraries/Image/RelativeImageStub'
},
Fixed by changing to this in jest.config.js:
moduleNameMapper: { // for https://github.com/facebook/jest/issues/919
'^image![a-zA-Z0-9$_-]+$': 'GlobalImageStub',
'^[@./a-zA-Z0-9$_-]+\\.(png|gif)$': 'RelativeImageStub',
},
Most helpful comment
Fixed by changing to this in jest.config.js: