I'm attempting to test a value that is set asynchronously using Jasmine 2's new done() callback.
I've based my test after the example Jasmine gives in their documentation (http://ift.tt/1IrTENk):
it('can set a flag after a delay', function(done) {
var flag = false,
setFlag = function() {
//set the flag after a delay
setTimeout(function() {
flag = true;
done();
}, 100);
};
setFlag();
expect(flag).toBe(true);
});
I'm getting the result "Expected false to be true", so I'm guessing that it's not waiting for the done() callback to be invoked before checking the value of the flag.
Does anyone know why this test is failing?
Thanks!
Aucun commentaire:
Enregistrer un commentaire