3

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.

brass monkey
  • 4,611
  • 10
  • 31
  • 52
A. L
  • 10,555
  • 20
  • 75
  • 142

1 Answers1

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
  • 36,719
  • 6
  • 95
  • 103