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.
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.
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