Javascript 如何在摩卡进行测试?
我不熟悉使用Mocha编写测试用例。我的nodejs中有以下功能。我想测试这个功能,但不知道该怎么做Javascript 如何在摩卡进行测试?,javascript,arrays,node.js,mocha.js,chai,Javascript,Arrays,Node.js,Mocha.js,Chai,我不熟悉使用Mocha编写测试用例。我的nodejs中有以下功能。我想测试这个功能,但不知道该怎么做 const notes = []; if (this.note) { notes.push(this.note); } if (message) { notes.push(message); } 下面是我试图实现的 it("Approve the request", async () => { assert.notEqual(this.status, null); ass
const notes = [];
if (this.note) { notes.push(this.note); }
if (message) { notes.push(message); }
下面是我试图实现的
it("Approve the request", async () => {
assert.notEqual(this.status, null);
assert.notEqual(this.status, "Pending");
expect(typeof const === []).to.be.true;// I got stuck here
assert.ok(true);
})
我哪里出错了?记住,测试用例将来自您的需求,而不是您的代码。因此,它应该涵盖需求中的所有情况,而不是代码。您的代码也需要涵盖所有需求 因此,从要求开始,我们可以说:
因此,您可以开始基于这些需求编写测试您可以测试功能,或者如果您是单元测试的话,可以测试对象的方法。在这里写下简单的方法。