【发布时间】:2015-11-02 00:18:59
【问题描述】:
我正在为使用 Node.js 和 Express 构建的应用程序编写 Jasmine 测试。第一个测试是查看应用程序是否响应 statusCode 200。我正在通过this tutorial 工作,它向您展示了如何做到这一点,但我遇到了障碍。
jasmine-node 不会运行测试。没有任何失败;它只是不提供报告。显然,this is a known bug.
看看jasmine-node project,不过一年多没更新了!查看主要的 jasmine 项目,我看到 it now has support for Node! 那么,是否已经放弃了 jasmine-node 以支持在 jasmine 中添加对 Node 的支持?在安装jasmine 并按照规范运行它之后,我现在遇到了一个新问题。当运行jasmine 或npm test 时,我得到的不是 Jasmine 测试失败,而是
Started
TypeError: Cannot read property 'statusCode' of undefined
这是我的规范文件:
var request = require("request");
var base_url = "http://localhost:3000/";
describe("Hello World Server", function() {
describe("GET /", function() {
it("returns status code 200", function(done) {
request.get(base_url, function(error, response, body) {
expect(response.statusCode).toBe(200);
done();
});
});
it("returns Hello World", function(done) {
request.get(base_url, function(error, response, body) {
expect(body).toBe("Hello World");
done();
});
});
});
});
【问题讨论】:
标签: javascript node.js jasmine jasmine-node