我正在尝试组合一个supertest
基于 的集成测试套件(由 Mocha 运行),它可以 ping 我们的 REST API 并验证响应。
但是,我的测试似乎没有按预期运行:
var assert = require('assert')
var should = require('should')
var request = require('superagent')
var WEBSERVICE_BASE = 'localhost:8080/our-application/'
describe('Authentication', function() {
it('prevents user from logging in without credentials', function() {
console.log('###')
console.log('Starting with: ' + request)
console.log('###')
request.get(WEBSERVICE_BASE + 'auth', function(err, res) {
console.log('Error: ' + err)
if (err) {
throw err
}
res.should.have.status(401)
done()
})
})
})
我在控制台中看到的内容:
Craigs-MBP:mocha-tests Craig$ ./run.sh
Authentication
###
Starting with: function request(method, url) {
// callback
if ('function' == typeof url) {
return new Request('GET', method).end(url);
}
// url first
if (1 == arguments.length) {
return new Request('GET', method);
}
return new Request(method, url);
}
###
✓ prevents user from logging in without credentials
1 passing (12ms)
它似乎request
被重新定义为一个函数,而不是superagent
对象?
测试不应该通过,至少应该看到console.log
打印参数。err