mardi 21 juillet 2020

"Cannot find module error" in my jest configuration file in a react-native project

I took over a project and I have a problem with jest and a mock in its configuration file I think ....
I have this error: "Cannot find module 'Alert' from 'jestsetup.js'"

I am using this version of jest: "jest": "^ 24.9.0", and this version of react-native: "62.2"

my configuration file is I think well referenced in my package.json:

"jest": {
    "preset": "react-native",
    "setupFiles": [
      "./test/jestsetup.js"
    ],
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ],
    "coverageReporters": [
      "lcov",
      "text"
    ],
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,mjs}",
      "!<rootDir>/**/*.stories.js"
    ],
    "testMatch": [
      "<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
      "<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
    ],
    "moduleNameMapper": {
      "^image![a-zA-Z0-9$_-]+$": "GlobalImageStub",
      "^[@./a-zA-Z0-9$_-]+\\.(png|gif)$": "RelativeImageStub"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "json",
      "web.jsx",
      "jsx",
      "node",
      "mjs"
    ],
    "coveragePathIgnorePatterns": [
      "<rootDir>/src/components/animations/Transitions",
      "<rootDir>/src/utils/helpers/analytics"
    ]
  },  

this is how the mock is made:

jest.mock("Alert", () => {
  return {
    alert: jest.fn()
  }
});

and the famous error:

enter image description here

If you have an idea ?

Aucun commentaire:

Enregistrer un commentaire