如何模拟或存根process.argv以便它可以返回特定参数?
我尝试像这样使用Sinon.js :
beforeEach(
() => {
sandbox.stub(
process.argv.slice(2)[0], 'C:\\home\\project\\assignment'
).value('--local');
}
);
afterEach(
() => {
sandbox.restore();
}
);
test(
'it replace value of node argument',
() => {
assert(process.argv.slice(2)[0], '--local');
}
);
Run Code Online (Sandbox Code Playgroud)
但我不断收到一个错误,提示试图'C:\\home\\project\\assignment'存根undefined.