【发布时间】:2022-11-25 15:17:29
【问题描述】:
我最近在使用 supertest 和 jest 的快速应用程序中遇到了以下测试代码
const supertest = require("supertest");
const app = require("../app");
const api = supertest(app);
test("notes are returned as json", async () => {
await api
.get("/api/notes")
.expect(200)
.expect("Content-Type", /application\/json/);
});
我对 .expect(200) 的来源感到困惑。这是supertest的一部分。因为我知道当我们调用 expect 时开玩笑,我们通常使用这样的匹配器:
expect(200).toBe(200)
但不知何故,这个测试不需要调用匹配器就可以工作。
【问题讨论】: