如何使用express,nodeJS和Mocha测试应用程序连接
问题描述:
我已经正确配置了我的应用程序,例如,如果我运行node app.js
,所有内容都将启动。我试图测试我的应用程序的连接正在使用单元测试正常工作。我至今是:如何使用express,nodeJS和Mocha测试应用程序连接
var options = {
url: 'http://localhost',
port: 8080,
};
var app = require("../app.js");
var should = require('should');
var assert = require("assert");
var async = require('async');
it ('tests the ok connection of the app by checking that it is listening on port 8080', function(dont) {
request(options,app)
.get('/')
.expect(200)
.end(function (err, res) {
res.header['location'].should.include('/')
res.text.should.include('Listening on port 8080');
done();
});
});
我收到错误消息Error: options.uri is a required argument
,这就是为什么我添加了var options
。现在我收到错误消息TypeError: Object #<Request> has no method 'get'
。
如何正确检查我是否有良好的连接(200
),我在正确的页面('/'
),并且在连接时记录消息Listening on port 8080
?
谢谢!
答
你只需要使用'request(app)'而不用选项。另外'应该'没有'.include',你需要使用'.containEql'。 – 2014-10-02 07:30:07