Created
June 17, 2014 08:13
-
-
Save Fintan/7697b8d1ddde7f01338c to your computer and use it in GitHub Desktop.
Jasmine Spy snippets
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
| 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