Skip to content

Instantly share code, notes, and snippets.

@Fintan
Created June 17, 2014 08:13
Show Gist options
  • Select an option

  • Save Fintan/7697b8d1ddde7f01338c to your computer and use it in GitHub Desktop.

Select an option

Save Fintan/7697b8d1ddde7f01338c to your computer and use it in GitHub Desktop.
Jasmine Spy snippets
var Person = function() {};
Person.prototype.helloSomeone = function(toGreet) {
return this.sayHello() + " " + toGreet;
};
Person.prototype.sayHello = function() {
return "Hello";
};
describe("Person", function() {
it("says hello", function() {
var fakePerson = new Person();
fakePerson.sayHello = jasmine.createSpy("Say-hello spy");
fakePerson.helloSomeone("world");
expect(fakePerson.sayHello).toHaveBeenCalled();
});
});
var obj = {
sayHello: function() {
}
};
var spy = spyOn(obj, 'sayHello').and.callThrough();
obj.sayHello();
expect(obj.sayHello).toHaveBeenCalled();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment