I am trying to create a separate suite of tests for component level testing of an app.
In this separate suite, I will need a custom test environment that bootstraps some persistence layer mocks and these tests will be housed in a separate folder in my project structure from my unit tests.
e.g. the unit tests will be nearby the code in __tests__
folders while the component tests will be in a top-level tests/
directory.
I already have most of my jest.config.js setup, but when I added the projects
section to override some of the fields, specifically testMatch
and testEnvironment
it completely disregarded my configuration specified in global.
Now I've been reading that the projects
configuration is mostly about monorepo setups, so I don't think that's the right approach.
Ideally I could just have a separate jest.config.js
in my tests/
directory, but I don't see how to set that up if that even works.
Any insight into this problem would be helpful. Thanks ahead of time.
To specify different config files you can use the --config
option.
For example if you have a tests/jest.config.js
file configuration for your component tests and a jest.config.js
file for your unit tests, you can configure the scripts in your package.json
so that they look something like this:
"scripts": {
"tests:unit": "jest --config=jest.config.js",
"tests:component": "jest --config=tests/jest.config.js"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With