jest-expect-message icon indicating copy to clipboard operation
jest-expect-message copied to clipboard

How to configure with existing setupTests.js

Open fljmayer opened this issue 4 years ago • 2 comments

This is probably just a documentation issue. I am on Jest 23, and I already have

"jest": {
    "setupTestFrameworkScriptFile": "<rootDir>src/react/setupTests.js"

Can I somehow initialize jest-expect-message within my setupTests.js file?

fljmayer avatar Sep 11 '19 15:09 fljmayer

Leaving comment here to help future travellers.

TL;DR: Add import 'jest-expect-message'; to your setupTests.ts file.

Long version: I rolled a fresh create-react-app with TypeScript app, which of course came with the setupTests.ts file. Note the file extension .ts. I installed this jest-expect-message dep together with @types/jest-expect-message. I added the above-mentioned import statement. Voila! It just works.

Though this is for .ts, I expect it to also just work with .js. Of course with JS you won't have to bother with installing the @types dep.

Hope this helps others.

saifulss avatar Apr 01 '20 15:04 saifulss

@saifulss Thank you very much!

roughpandaz avatar Feb 07 '22 01:02 roughpandaz

I've added this advice to the projects readme so will go ahead and close this. Thanks!

mattphillips avatar Sep 08 '22 17:09 mattphillips