【问题标题】:does jest have a --require command like mochajest 有没有像 mocha 这样的 --require 命令
【发布时间】:2018-10-26 06:00:29
【问题描述】:

Jest 是否有类似 mocha 的 --require 的选项?我宁愿在命令行中使用--require 之类的选项,而不是在每个文件的标题中添加require(x)

【问题讨论】:

    标签: javascript jestjs


    【解决方案1】:

    Jest 配置提供setupFilessetupTestFrameworkScriptFile 可用于在测试运行之前运行设置代码。

    require(x) 语句需要执行所有需要的副作用,无法从设置文件中的 require 语句访问 x 的模块导出,但它看起来像that is exactly how the --require option works in Mocha.

    只需创建一个调用require(x) 的设置文件,然后使用上面列出的两个选项之一或pass it on the command line using the --setupTestFrameworkScriptFile option 将其添加到Jest 配置中

    【讨论】:

      猜你喜欢
      • 2020-02-07
      • 1970-01-01
      • 1970-01-01
      • 2011-01-21
      • 1970-01-01
      • 2020-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多