Testing two environments with jest
EDIT (Jan 2018):
It is now possible to do so (since Jest v20), and the option is called projects
. Read more about it the docs.
Basically you can define an array of your projects you want Jest to be run within:
{
"projects": ["<rootDir>/client", "<rootDir>/server", "<rootDir>/some-glob/*"]
}
Just remember every project needs to have its own config. If you want the config to be picked up automatically, put it inside jest.config.js
file or like usually in package.json
.
If you prefer placing your config somewhere else (e.g. in configs/jest.js
), you'll need to point to the path of the config file (with the rootDir
option set properly):
{
"projects": ["<rootDir>/client/configs/jest.js", "<rootDir>/server/configs/jest.js"]
}
ORIGINAL ANSWER:
Currently this is not possible, but there's an issue for that case: https://github.com/facebook/jest/issues/1206.
Feel free to jump in and leave a comment!
You can also use the @jest-environment
docblock to set test environments on a per-file basis:
/**
* @jest-environment jsdom
*/
test('use jsdom in this test file', () => {
const element = document.createElement('div');
expect(element).not.toBeNull();
});