如何在摩卡咖啡中测试?

时间:2018-09-27 05:45:14

标签: javascript arrays node.js mocha 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);
    assert.notEqual(this.status, "Pending");
    expect(typeof const === []).to.be.true;// I got stuck here
    assert.ok(true);
  })

我要去哪里错了?

1 个答案:

答案 0 :(得分:1)

记住测试用例将来自您的要求,而不是您的代码。因此,它应该涵盖您的要求中的所有情况,而不是您的代码。您的代码也需要满足所有要求。

所以从需求开始,我们会说:

  1. 该功能应将注释和消息添加到notes数组。

  2. 如果便笺为空,则函数应忽略便笺。

  3. 如果消息为空,该函数应忽略消息。

  4. 如果两个都为空,则函数应返回空数组。

因此您可以根据这些要求开始编写测试