Skip to content

Instantly share code, notes, and snippets.

@badbabykosh
Forked from pkananen/set-interval-spec.js
Last active September 4, 2015 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badbabykosh/8dfae89e3943df0fadd5 to your computer and use it in GitHub Desktop.
Save badbabykosh/8dfae89e3943df0fadd5 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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment