1

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

1 回答 1

0

来自超级代理文档

响应头字段

res.header 包含已解析的标头字段的对象,字段名称小写,就像节点一样。例如 res.header['content-length']。

因此,您可以检查以下内容:

(/home$/).test res.header['location']

对于您的重定向测试用例。

于 2012-02-28T06:21:04.067 回答