Skip to content

Instantly share code, notes, and snippets.

@MandarinConLaBarba
Created May 15, 2012 22:03
Show Gist options
  • Save MandarinConLaBarba/2705492 to your computer and use it in GitHub Desktop.
Save MandarinConLaBarba/2705492 to your computer and use it in GitHub Desktop.
Jasmine Spies: Mocking
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();
});
});
var testModule2 = require('./testModule2');
exports.testMethod = function() {
return testModule2.doIt();
};
exports.doIt = function() {
return "this is the real thing..";
};
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