【发布时间】:2014-09-02 03:56:00
【问题描述】:
我正在构建一个 API,并尝试使用 mocha 和 supertest 对其进行测试。
我正在使用此代码正确测试 POST 调用:
it("Should generate a PDF based on the given data using API", function(done) {
request(app)
.post("/api/document/print")
.send({tplName: "default", tplData: { title: "Testee", p1: "paragraph"}})
.expect(200, done);
});
但是当我尝试使用此代码测试 GET 请求时:
it("Should get HTML of the selected template", function(done) {
request(app)
.get("/api/template/default/html")
.expect(200, done);
});
测试失败,如果我运行我的应用并在 Chrome 中尝试,我会得到正确的响应 (200)。
我做错了什么?
【问题讨论】:
-
我不知道。测试失败时会说什么?
-
好吧..没什么。它只是失败了。
-
你的测试没有给你任何输出?
-
npm ERR! Test failed. See above for more details.但上面什么都没有。 -
你在 package.json 中的
scripts.test命令是什么(如果是make test,那么你的 Makefile 中的test是什么)?