I would recommend adding a callCount
variable, and incrementing it by 1 each time a callback is invoked. Then you can expect(callCount).toBe(x)
just before the call to done()
.
On the other hand, you can use Spies to achieve this as well:
it("Should run callbacks with correct data", function(done){
var callback = jasmine.createSpy("callback");
var actuallyDone = function() {
expect(callback.calls.count()).toBe(2);
expect(callback.calls.all()[0].args[0]).toEqual({a:1, b:2});
expect(callback.calls.all()[1].args[0]).toEqual({a:1, b:2});
done();
};
test.fastResponse(callback);
test.fastResponse(callback);
test.slowResponse(function(data){
expect(data).toEqual({a:1, b:2});
actuallyDone();
});
});