Jest cannot find custom environment in @jest-environment docblock
See original GitHub issue🐛 Bug Report
When I added a @jest-environment
docblock to a test suite (name1.test.js
) I got below error when running test:
Validation Error:
Test environment MongoEnvironment cannot be found. Make sure the testEnvironment configuration option points to an existing node module.
But if I comment out line 2 in name1.test.js
(to remove @jest-environment
), my custom test environment named MongoEnvironment
is working well, line 11 in mongo-environment.js
works correctly. It means Jest is configured well, isn’t it?
To Reproduce
- Clone https://github.com/tiendq/haypley-services
- Checkout branch
test/reproduce-jest-docblock-error
yarn install
yarn test name1.test.js
Expected behavior
Test runs well. No error.
Link to repl or repo (highly encouraged)
https://github.com/tiendq/haypley-services
envinfo
System:
OS: macOS 10.14.5
CPU: (4) x64 Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
Binaries:
Node: 10.16.3 - /usr/local/opt/node@10/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/opt/node@10/bin/npm
npmPackages:
jest: ^24.8.0 => 24.8.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Set custom Jest environment in docblock - Stack Overflow
Yes, you can set a custom environment for a single Jest test using the docblock syntax. If your custom environment is installed as...
Read more >Configuring Jest
Any docblock pragmas in test files will be passed to the environment constructor and can be used for per-test configuration. If the pragma...
Read more >Configuring Jest compiled - w3resource
Any docblock pragmas in test files that are passed to the environment constructor and can also be used for per-test configuration. In the...
Read more >jest: configuring test environments - code-comments
Add a @jest-environment doc block. Note: The docs suggest that this approach works, however, it did not work in my experience. Perhaps a...
Read more >Jest Runner | Stryker Mutator
Don't worry; using Stryker's alternative is harmless during regular unit testing. If you're using a custom test environment, you'll need to mixin the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The docs should probably explicitly state that the value of the pragma must be a requireable module (so either something in
node_modules
or a relative path to some other module), not just a name. Wanna contribute that change to the docs?EDIT: What he said 🙂
Jest has no way to find the environment just based on the string
MongoEnvironment
. If you specify* @jest-environment ./test/jest/mongo-environment.js
it works.