Does Jest have a similar option like mocha's --require
? I would prefer to have an option like --require
in the command line rather than putting a require(x)
in the title of every file.
Asked
Active
Viewed 276 times
3

brass monkey
- 5,841
- 10
- 36
- 61

A. L
- 11,695
- 23
- 85
- 163
1 Answers
4
Jest
configuration provides setupFiles
and setupTestFrameworkScriptFile
which can be used to run setup code before tests run.
The require(x)
statement would need to perform all of the needed side-effects, there isn't a way to access the module exports of x
from a require
statement in the setup file, but it looks like that is exactly how the --require option works in Mocha.
Just create a setup file that calls require(x)
and either add it to the Jest
config using one of the two options listed above or pass it on the command line using the --setupTestFrameworkScriptFile
option

Brian Adams
- 43,011
- 9
- 113
- 111