我正在用Ember-qunit编写单元测试。我想在Performance.now上设置自定义值。
我尝试过sinon.stub(performance,'now', 60000);
,但这没用。我得到TypeError: stub(obj, 'meth', fn) has been removed.
我如何使用sinon.js存根Performance.now()?
谢谢
[不确定您的第三个参数(60000
)应该是什么,因为我不熟悉performance.now()
,但这不是对Sinon.stub()
(there is no 3rd parameter)的有效调用。但是根据文档,您应该能够捕获存根函数,然后在其上调用方法以指示所需的返回值:
const stub = sinon.stub(performance, 'now');
stub.returns(60000);
然后,当存根被调用时,您应该得到:
console.log( stub() ); // 60000
您可以在此jsfiddle example中看到此功能。