I have been experimenting with using doh.Deferred to create a test that verifies the following sequence of events:
- Login with user A (asynchronous)
- Log out (synchronous)
- Login again with user A (asynchronous)
The second callback function's return value is another doh.Deferred object. I expected the callback chain of d to wait for d2, but that doesn't happen. The test completes before d2.callback is triggered.
Can anyone point out where I might be making a mistake in my approach?
Is there a more effective way for me to conduct this test?
function test() {
var d = new doh.Deferred();
d.addCallback(function() {
Comm.logout(); /* synchronous */
try {
// validate using doh.t and doh.is
return true;
} catch (e) {
d.errback(e);
}
});
d.addCallback(function() {
var d2 = new dojo.Deferred();
/* asynchronous - third parameter serves as a callback */
Comm.login('alex', 'asdf', function(result, msg) {
try {
// validate using doh.t and doh.is
d2.callback(true);
} catch (e) {
d2.errback(e);
}
});
return d2; // returning doh.Defferred -- expecting d to wait for d2.callback
});
/* asynchronous - third parameter serves as a callback */
Comm.login('larry', '123', function (result, msg) {
try {
// validate using doh.t and doh.is
d.callback(true);
} catch (e) {
d.errback(e);
}
});
return d;
}