Created
July 27, 2012 19:17
-
-
Save fivetanley/3189933 to your computer and use it in GitHub Desktop.
requirejs mocking
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
// what are you trying to mock...? | |
function Class1() { | |
this.class2var = new Class2() | |
} | |
function Class2() { | |
throw new Error( 'not implemented or too hard to test against' ) | |
} | |
// test | |
// do you want to stub out class2? | |
// substitute the class 2 function | |
// and also return an array | |
Class2 = stub.create().andReturn( [] ) | |
// bleh, too lazy to write the function | |
// check that the class doesn't throw. if we didn't fake out the Class2 | |
// constructor, it would throw and the test would fail | |
assert( new Class1() , doesNotThrow ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment