when I run this code below, the user is logged in and the browser is redirected to a new route home
. How do I structure the test below to validate that /home
is being redirected to.
The application is working fine, I am just trying to get my test cases in order.
Thanks
it('should login user',
function(done) {
request
.post(url.parse('http://localhost:3000/login'))
.send({
userName: "[email protected]", password: "xyzpassword"
})
.end(function(res) {
res.statusCode.should.equal(302);
done();
})
});
additional information... the code works but is failing with the stackdump so I am unable to verify that the test is successful or not
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)
From the superagent docs
Response header fields
The res.header contains an object of parsed header fields, lowercasing field names much like node does. For example res.header['content-length'].
So you can check along the lines of:
(/home$/).test res.header['location']
For your redirect test case.