Slide 57
Slide 57 text
ASYNC TESTING
describe(“Shark”, function() {
it(‘say something after finish eating’, function() {
var shark = new Shark();
spyOn(shark, ‘say’);
runs(function() { // start the async support
shark.eat(‘duck’);
});
waitsFor(function() { // wait for something happen and return true, or it will time out
return shark.say.callCount == 1;
}, “Shark should say something”, 500);
runs(function() { // still inside the async support
expects(shark.say.callCount).toBeGreaterThan(0);
});
}
});