当我在下面运行此代码时,用户已登录并且浏览器被重定向到新路由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)