【发布时间】:2019-09-02 11:48:26
【问题描述】:
我有以下代码,用于启动设备命令类。
class DeviceCommand {
/**
* DeviceCommand constructor.
*
* @param {String} cmd - The command to send.
* @param {String} ack - The acknowledgement from the device.
*/
constructor(cmd, ack) {
if (arguments.length !== 2) {
throw new Error('Expected at least 2 paramters');
}
this.cmd = cmd;
this.ack = ack;
}
}
我想测试这个类是否被 new 调用,使用下面的
const ClassStub = sandbox.spy(() => sinon.createStubInstance(DeviceCommand));
ClassStub.should.have.been.calledWithNew;
但是,这实际上并没有执行测试,因为以下也通过了
ClassStub.should.not.have.been.calledWithNew;
虽然,以下失败
sinon.assert.calledWithNew(ClassStub);
不应该那样做吗?谢谢。
【问题讨论】:
标签: node.js mocha.js sinon chai