Created
July 14, 2011 17:55
-
-
Save schovi/1082984 to your computer and use it in GitHub Desktop.
Hax of setTimeout with Jasmine test framework. Works only if setTimeout doesn't affect correct work of program.
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("My amazing lib", function() { | |
beforeEach(function() { | |
this.oldSetTimeout = window.setTimeout; | |
window.setTimeout = function(cb) { cb() }; | |
}) | |
it("should correct process method with setTimeout", function() { | |
var instance = new MyLib(); | |
instance.processMethodWithSetTimeout(); | |
expect(instance.resultOfThatMethod).toBe("done"); | |
}) | |
afterEach(function() { | |
window.setTimeout = this.oldSetTimeout; | |
}) | |
}) |
Hah. Because i was half day old user of that :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any reason you don't just do a
spyOn(window, 'setTimeout')
?