In general, you'll need to use waitsFor to test async code. It sounds like you'll need to add a test jig, where your async function sets a variable that the function called by waitsFor will check.
-- Sent from my HP Pre 3
On Aug 3, 2012 10:35 AM, Stefan <chrobot.stefan@gmail.com> wrote:
Hi, I'm trying to test some async code. The thing is that it's written by me and I always have a handler whenever I have an async call:
var srv = {
getAsync: function (handler) {
setTimeout(function () {
handler('success');
}, 10);
}
};
Do I need to mock the clock or use the runs/waitsFor to test it or is it enough for me to put the expectations in the handlers like this:
describe('srv', function () {
it('works', function () {
srv.getAsync(function (x) {
expect(x).toBe('success')
});
});
});
I would need to mock the clock or use runs/waitsFor if I wanted to test if the handler was actually called, right?
If so, which of these methods (mock or runs/waitFor) is preferred?
Stefan
--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/jasmine-js/-/P1VTKj5JKY0J.
To post to this group, send email to jasmine-js@googlegroups.com.
To unsubscribe from this group, send email to jasmine-js+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.