使用本机节点模拟来模拟进程argv

问题描述 投票:0回答:1

我正在从

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”必须是方法。收到未定义

node.js testing mocking node-test-runner
1个回答
0
投票

我从未找到解决方案(并使用本机模拟库模拟许多其他本机库),但在这种情况下,我做了明显的事情并将 argv 注入到函数中,并且没有直接测试它

© www.soinside.com 2019 - 2024. All rights reserved.