Skip to content

Instantly share code, notes, and snippets.

@pkananen
Last active February 8, 2016 20:56
Show Gist options
  • Save pkananen/1005165 to your computer and use it in GitHub Desktop.
Save pkananen/1005165 to your computer and use it in GitHub Desktop.
testing setInterval with Jasmine using a Mock Clock
describe('createIntervalCallback', function() {
var sut = $.clockTest;
it('calls setInterval with callback() at a delay of 7000 ms', function() {
spyOn(sut, 'callback');
jasmine.Clock.useMock();
sut.createIntervalCallback();
jasmine.Clock.tick(7000);
expect(sut.callback).toHaveBeenCalled();
});
});
(function($) {
$.clockTest = $.clockTest || {};
$.extend($.clockTest, {
createIntervalCallback: function() {
setInterval(function() { $.clockTest.callback(); }, 7000);
},
callback: function() {
// do stuff...
}
});
}(jQuery));
@badbabykosh
Copy link

would you be so kind as to post a non jquery version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment