3

I have faced following problem. FYI, I am a beginner for the Jest, so please let me know what's wrong in configuring Jest.

webpack.config.js

...

resolve: {
  extensions: ['.ts', '.tsx', '.js', '.json', '.scss'],
  alias: {
    'webextension-polyfill-ts': path.resolve(
      path.join(__dirname, 'node_modules', 'webextension-polyfill-ts')
    ),
    reducers: path.resolve(__dirname, 'source/redux'),
    routers: path.resolve(__dirname, 'source/routers'),
    source: path.resolve(__dirname, 'source'),
    ...
  },
},

...

Here's the Jest configuration in package.json

"jest": {
  ...
  "moduleNameMapper": {
    "^reducers": "<rootDir>/source/redux/$1",
    "^routers": "<rootDir>/source/routers/$1",
    "^source": "<rootDir>/source/$1",
    ...
  }
  ...
}

But I got following error while run a test file.

Configuration error:
    
Could not locate module source-map-support mapped as:
/Volumes/WORK/Development/project/source/$1.
    
Please check your configuration for these entries:
{
  "moduleNameMapper": {
    "/^source/": "/Volumes/WORK/Development/project/source/$1"
  },
  "resolver": undefined
}

1 Answer 1

6

The issue looks like from you set the wrong pattern for moduleNameMapper. The right one is supposed to be:

{
  "moduleNameMapper": {
    "^reducers/(.*)$": "<rootDir>/source/redux/$1", // You missed the 2nd part `/(.*)`
    // ...
    ...
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.