Jest 是否有类似 mocha 的 --require
的选项?我更愿意在命令行中使用像 --require
这样的选项,而不是在每个文件的标题中放置 require(x)
。
最佳答案
Jest
配置提供setupFiles
和 setupTestFrameworkScriptFile
可用于在测试运行之前运行设置代码。
require(x)
语句需要执行所有需要的副作用,没有办法从require
语句在设置文件中,但它看起来像 that is exactly how the --require option works in Mocha .
只需创建一个调用 require(x)
的设置文件,然后使用上面列出的两个选项之一或 pass it on the command line using the --setupTestFrameworkScriptFile
option 将其添加到 Jest
配置中
关于javascript - jest 有像 mocha 这样的 --require 命令吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53002361/