When I try to run a test in jest that imports a file using the $lib alias, jest fails to run with the error Cannot find module '$lib/...'.
When I try to run a test in jest that imports a file using the $lib alias, jest fails to run with the error Cannot find module '$lib/...'.
Add the following to jest.config.cjs:
module.exports = {
...,
moduleNameMapper: { '^\\$lib(.*)$': '<rootDir>/src/lib$1' },
}
The documentation can be found under Using with webpack.