Skip to content

Instantly share code, notes, and snippets.

@schovi
Created July 14, 2011 17:55
Show Gist options
  • Save schovi/1082984 to your computer and use it in GitHub Desktop.
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.
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;
})
})
@aakashd
Copy link

aakashd commented Jul 28, 2011

Any reason you don't just do a spyOn(window, 'setTimeout')?

@schovi
Copy link
Author

schovi commented Aug 16, 2011

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