我正在从
sinon
迁移到本机 node:test
库。
在我像这样用
sinon
嘲笑 argv 之前;
import { stub } from 'sinon'
stub(process, 'argv').get(() => ['node-path', 'application-entry', 'first-arg']
以下带有
node:test
的内容不起作用;
import { mock } from "node:test"
mock.getter(Process, 'argv').mock.mockImplementation(() => ['node-path', 'application-entry', 'first-arg'])
我收到以下错误;
TypeError [ERR_INVALID_ARG_VALUE]:参数“methodName”必须是方法。收到未定义
我从未找到解决方案(并使用本机模拟库模拟许多其他本机库),但在这种情况下,我做了明显的事情并将 argv 注入到函数中,并且没有直接测试它