gpt4 book ai didi

javascript - 检查 qunit 中是否有两个异步调用

转载 作者:行者123 更新时间:2023-11-28 20:58:47 25 4
gpt4 key购买 nike

如何编写这样的场景:我有一个操作生成两个异步回调,并且我希望测试在调用两个回调时结束?

asyncTest('Do two asynchronous things', 2, function() {
doTwoThings(callback1, callback2);
function callback1() {
ok(true, 'dummy test');
start();
}
function callback2() {
ok(true, 'dummy test');
start();
}
});

最佳答案

答案是使用您期望的额外启动次数来调用 stop。 asyncTest 需要一个启动,因此对于我的情况,我必须添加另一个调用来停止。

asyncTest('Do two asynchronous things', 2, function() {
stop()
doTwoThings(callback1, callback2);
function callback1() {
ok(true, 'dummy test');
start();
}
function callback2() {
ok(true, 'dummy test');
start();
}
});

关于javascript - 检查 qunit 中是否有两个异步调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11565705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com