我希望运行一个定义在我的玩笑测试中多次重复使用的常量和函数的脚本,有什么方法可以做到这一点吗?例如始终运行的 setup.spec.js 或在命令行中定义参数(例如 npm jest -setup 等)?
jest.config.js 中有一个用于此目的的选项:
// The paths to modules that run some code to configure or set up the testing environment before each test
setupFiles: [
'./mySetupScript.js'
],
Run Code Online (Sandbox Code Playgroud)
笑话 v24.8.0