0
我试图用doh.Deferred编写测试,将检查以下事件调用序列:是否有可能测试异步函数序列与DOH
- 登录与用户A(异步)
- 注销(同步)
- 登录与用户A(异步)
第二回调函数的返回值是另一个doh.Deferred对象。我的印象是,d的回调链将等待d2,但它不会。测试在d2.callback被调用之前完成。
我在哪里错了?
有没有人知道更好的方式来测试这种行为?
function test() {
var d = new doh.Deferred();
d.addCallback(function() {
Comm.logout(); /* synchronus */
try {
// check with doh.t and doh.is
return true;
} catch (e) {
d.errback(e);
}
});
d.addCallback(function() {
var d2 = new dojo.Deferred();
/* asynchronus - third parameter is a callback */
Comm.login('alex', 'asdf', function(result, msg) {
try {
// check with doh.t and doh.is
d2.callback(true);
} catch (e) {
d2.errback(e);
}
});
return d2; // returning doh.Defferred -- expect d to wait for d2.callback
});
/* asynchronus - third parameter is a callback */
Comm.login('larry', '123', function (result, msg) {
try {
// check with doh.t and doh.is
d.callback(true);
} catch (e) {
d.errback(e);
}
});
return d;
}