Skip to content

Instantly share code, notes, and snippets.

@fivetanley
Created July 27, 2012 19:17
Show Gist options
  • Save fivetanley/3189933 to your computer and use it in GitHub Desktop.
Save fivetanley/3189933 to your computer and use it in GitHub Desktop.
requirejs mocking
// 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