我正在尝试使用mocha和chai为我的可观察方法编写测试,该方法调用服务器并返回一些json数据 . 但是,当我运行测试时,我收到以下错误: Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. 即使我覆盖默认的超时时间,我仍然会收到上述错误 . 我究竟做错了什么 ?
describe("some test", () => {
let someClass: SomeClass;
before(() => {
someClass = new SomeClass();
});
;
it("should meet some condition", done => {
let getData = someClass.getData('query')
getData.subscribe(json => {
json.success.should.equal(true);
done();
},
done
);
});
});
1 回答
我找到了一个解决方案,我在前挂钩中调用
done()
,在每个it()
函数上调用超时 .