-
-
Save badbabykosh/8dfae89e3943df0fadd5 to your computer and use it in GitHub Desktop.
testing setInterval with Jasmine using a Mock Clock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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