Created
May 15, 2012 22:03
-
-
Save MandarinConLaBarba/2705492 to your computer and use it in GitHub Desktop.
Jasmine Spies: Mocking
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
var testModule = require("./testModule"), | |
testModule2 = require('./testModule2'); | |
describe("mock/spy test", function() { | |
it("should not pass", function(done) { | |
var theNewValue = "this is a mock, sucker!" | |
var spy = spyOn(testModule2, 'doIt').andCallFake(function () { | |
return theNewValue; | |
}); | |
expect(testModule.testMethod()).toBe(theNewValue); | |
done(); | |
}); | |
}); |
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
var testModule2 = require('./testModule2'); | |
exports.testMethod = function() { | |
return testModule2.doIt(); | |
}; |
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
exports.doIt = function() { | |
return "this is the real thing.."; | |
}; |
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
mock/spy test | |
should pass | |
Finished in 0.006 seconds | |
1 test, 1 assertion, 0 failures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment