-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Jest tests work better with TypeScript #2558
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few non-blocking comments in the review. Only thing is I tested the case reported on #2535 and it still throws the exception.
import { lightColors } from 'lib/colors' // Line 7 of lib/utils.tsx
FAIL frontend/src/lib/utils.test.ts
● Test suite failed to run
Configuration error:
Could not locate module lib/colors mapped as:
./src/lib/$1.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^lib\/(.*)$/": "./src/lib/$1"
},
"resolver": undefined
}
5 | import moment from 'moment'
6 | import { EventType } from '~/types'
> 7 | import { lightColors } from 'lib/colors'
Also, might be worth for someone with stronger expertise on Jest to take a look, but if we can fix the case described above, IMO it's good to go.
Hm, yes, the problem from #2535 does persist and I honestly have no idea how to fix it. 🤔 |
Maybe it's worth merging this PR anyways, though it seems like #2535 is not resolved yet. It's not an issue right now, but it might become an issue later as we start adding more unit tests to files that have absolute imports. |
@paolodamico Actually ended up not using ts-jest, but this seems to resolve #2535 nevertheless. 🤔 Take a look please, maybe we can merge. |
Changes
ts-jest is a way to make Jest work smoothly with TypeScript. Should resolve #2535.
Checklist