我正在使用promises测试我的休息应用程序(使用hapi on node)和mocha(3.2)以及supertest(3.0) .
它在超时后停止并返回错误:
错误:超出2000ms的超时 . 对于异步测试和钩子,确保调用“done()”;如果返回Promise,请确保它已解决 .
我已经尝试增加超时但它没有用 .
如果我添加一个 done()
电话我得到:
分辨率方法过于规范 . 指定回调或返回Promise;不是都 .
请问你能帮帮我吗?
这是我的测试:
...
const request = require('supertest');
const redis = require('redis');
const bluebird = require("bluebird");
bluebird.promisifyAll(redis.RedisClient.prototype);
const config = require('../src/config/tests');
describe('Routing', function () {
let url = 'http://localhost:8080';
let storage = redis.createClient({
host: config.config.host,
port: config.config.port
});
it('should pass', function (done) {
let username = 'user',
userHash = md5(username),
data = {
user_id: username,
sess_id: 'session'
};
return storage.delAsync("users:" + userHash)
.then(result => {
return request(url)
.post('/login')
.send(data)
.expect(201)
.expect({info: true});
})
.then(response => {
return storage.hgetallAsync("users:" + userHash);
})
.then(result => {
assert({user_id: userHash}, result);
})
});
});
1 回答
在函数签名中指定
done
参数将测试标记为异步 . 而不是调用它会导致待测试 .如果使用
function (done) { ... }
指定,则应调用它 . 这就是错误所说的 . 并且不应该指定是否通过返回promise来使规范异步 .