我有一个 utility.js,它通过 process.argv
使用程序参数。
当我运行 jest -t 'utility-spec' --arg1 value1 --arg2 value2
时,它抛出异常。无法运行测试。
(node:8956) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ● Unrecognized CLI Parameters:
Following options were not recognized: ["arg1", "arg2"]
最佳答案
刚刚遇到同样的问题并找到了答案:
Jest doesn't accept node arguments unfortunately. I recommend testing your utility by making a programmatic interface. You can also overwrite process.argv in your test before requiring your module.
好像不可能。
关于node.js - 如何在 Jest 测试中发送 Node 命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47610880/