我在NodeJS中有一个Mocha测试:
it('Test', async () => {
this.party = new Party('example_id');
await this.party.startWithPlaylist('3e8JNsQmYEXtfV7K1M0pAb');
assert.isTrue(this.party.getStreamingProvider().getAuth().getToken() !== undefined);
})其中this.party.startWithPlaylist为:
startWithPlaylist(id) {
return new Promise(async (resolve, reject) => {
assert.ok(id !== undefined);
await this.start();
let playlist = await this.songInfoProvider.getPlaylist(id);
resolve();
});
}代码运行正常,但我的测试没有正常运行。在开始测试2秒后,我得到了错误:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.错误发生后,startWithPlaylist会正确完成,但似乎不能及时完成我的测试。
我查看了Stackoverflow,发现了类似的问题,但没有一个有公认的答案或任何其他对我有效的提示。我已经尝试将测试从async更改为只等待使用.then解决的承诺,但我的尝试都没有成功。
如果有任何帮助,我将不胜感激!提前感谢!
发布于 2021-01-21 00:22:00
这里的问题是函数需要执行的时间比提供的超时时间要长。
Yo可以通过多种方式使用this.timeout(...)进行更改。文档here
一种方式是这样,但存在多个选项:套件/测试/钩子级别...
it('Test', async () => {
this.party = new Party('example_id');
await this.party.startWithPlaylist('3e8JNsQmYEXtfV7K1M0pAb');
assert.isTrue(this.party.getStreamingProvider().getAuth().getToken() !== undefined);
}).timeout(4000)或者在以这种方式运行mocha时使用parameters in command line:
mocha test --timeout 4000发布于 2021-01-20 23:22:33
你真的定义了arg。"id“在运行的时候?
https://stackoverflow.com/questions/65812421
复制相似问题