【发布时间】:2014-05-15 14:16:23
【问题描述】:
我正在尝试使用 Mocha 和 SuperAgent 的 TDD 方法,但是当来自 SuperAgent 的 res.text 不知何故未定义时卡住了。
测试:
it('should return 2 given the url /add/1/1', function(done) {
request
.get('/add/1/1')
.end(function(res) {
res.text.should.equal('the sum is 2');
done();
});
});
代码:
router.get('/add/:first/:second', function(req, res) {
var sum = req.params.first + req.params.second;
res.send(200, 'the sum is ' + sum);
});
【问题讨论】:
-
我都试过了,应该都支持。
-
您检查
res.statusCode以确保它是200? -
不错,它是 404!
-
这个工作:
.get('http://localhost:3000/add/1/1') -
你如何设置请求
标签: node.js express mocha.js superagent