Unverified Commit 2be207a2 authored by Dan Page's avatar Dan Page Committed by GitHub

Add moduleDirectories for TS Jest Config (#32574)

It took me a while to work out that if using TypeScript with the `baseUrl` set to `.` (quite common) - then the tests fail as Jest can't find the modules.

Explicitly setting the `moduleDirectories`, as per the change to the config, fixes this issue.



## Documentation / Examples

- [x] Fixup commit
- [x] Make sure the linting passes by running `yarn lint`
parent 83b04c89
...@@ -282,6 +282,8 @@ const createJestConfig = nextJest({ ...@@ -282,6 +282,8 @@ const createJestConfig = nextJest({
// Add any custom config to be passed to Jest // Add any custom config to be passed to Jest
const customJestConfig = { const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
moduleDirectories: ['node_modules', '<rootDir>/'],
} }
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async // createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment