当我在下面运行此代码时,用户已登录,浏览器将重定向到新路由home
。如何构建下面的测试以验证/home
是否被重定向到。
应用程序运行正常,我只是想让我的测试用例按顺序完成。
由于
it('should login user',
function(done) {
request
.post(url.parse('http://localhost:3000/login'))
.send({
userName: "load@xyz.com", password: "xyzpassword"
})
.end(function(res) {
res.statusCode.should.equal(302);
done();
})
});
附加信息......代码可以工作,但是堆栈转储失败,所以我无法验证测试是否成功
1) authentication_tests should login user:
TypeError: first argument must be a string, Array, or Buffer
at ClientRequest.write (http.js:601:11)
at ClientRequest.end (http.js:681:16)
at Request.end (/Users/aaronksaunders/dev/node_stuff/sqchic/node_modules/superagent/lib/node/index.js:602:7)
at Request.redirect (/Users/aaronksaunders/dev/node_stuff/sqchic/node_modules/superagent/lib/node/index.js:459:8)
at ClientRequest.<anonymous> (/Users/aaronksaunders/dev/node_stuff/sqchic/node_modules/superagent/lib/node/index.js:569:49)
at ClientRequest.emit (events.js:64:17)
at HTTPParser.<anonymous> (http.js:1349:9)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1226:22)
at Socket._onReadable (net.js:683:27)
at IOWatcher.onReadable (net.js:177:10)
答案 0 :(得分:0)
响应标头字段
res.header包含一个解析的头字段对象,小写字段名称与节点一样。例如res.header ['content-length']。
所以你可以检查:
(/home$/).test res.header['location']
对于重定向测试用例。