jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.26k stars 508 forks source link

Custom jest.config.js #695

Closed imteekay closed 4 years ago

imteekay commented 4 years ago

I'm trying TSDX with React. And as I'm using toBeInTheDocument function from @testing-library/jest-dom, I need to import it in my test file.

But it would be awesome to add this import statement in the jest setup configuration instead of all test files I create.

Are there any way to TSDX read the "custom" jest.setup.js?

Thanks in advance!

Oreoz commented 4 years ago

I don't know if that's the prescribed way to do it, but I simply added two files to my root directory and it works like a charm.

// jest.config.js
module.exports = {
  verbose: true,
  setupFilesAfterEnv: ["./setupTests.ts"],
};
// setupTests.ts
import "@testing-library/jest-dom";
imteekay commented 4 years ago

Thanks, @Oreoz! It really works like a charm.

agilgur5 commented 4 years ago

Yes, you can use pacakge.json.jest or jest.config.js to further configure Jest; it'll be shallow-merged with TSDX's built-in config.

jest.config.js has been supported since #229 -- this is actually a duplicate of #100. Please search the issues before reporting one.

Have a TODO to add some more docs around this as this isn't as explicit as it can be in the docs, but tsdx test is just a small wrapper around Jest.