Created
October 22, 2010 01:40
-
-
Save stevehorn/639760 to your computer and use it in GitHub Desktop.
How do I stub and/or redefine a javascript object dependency?
This file contains hidden or 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
//Code under test | |
function Foo() { | |
this.do_something_interesting = function() { | |
var dependency = new CanYouMockMe(); | |
if(dependency.i_want_stubbed() === true) { | |
//do stuff based on condition | |
} else { | |
//do stuff if false | |
} | |
} | |
} | |
//Test Code | |
describe("Foo", function () { | |
it("should do something if the dependency returns true", function () { | |
var foo = new Foo(); | |
//how do I stub and/or redefine the "i_want_stubbed" method here? | |
var result_if_true = foo.do_something_interesting(); | |
expect(result).toEqual(result_if_true); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment