Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure jest to handle SvelteKit's `$lib` alias?

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/...'.

like image 223
David Avatar asked Dec 31 '25 16:12

David


1 Answers

Add the following to jest.config.cjs:

module.exports = {
  ...,
  moduleNameMapper: { '^\\$lib(.*)$': '<rootDir>/src/lib$1' },
}

The documentation can be found under Using with webpack.

like image 91
David Avatar answered Jan 03 '26 23:01

David



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!