Created
August 22, 2012 16:35
-
-
Save timwingfield/3427271 to your computer and use it in GitHub Desktop.
constructor spying spike
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
describe("Spying on a window object", function() { | |
describe("working with the object", function() { | |
beforeEach(function () { | |
this.name = "Spongebob"; | |
this.subject = new Klass(this.name); | |
}); | |
it("should have properties", function() { | |
expect(this.subject.properties).toBeDefined(); | |
}); | |
it("should set the name", function() { | |
expect(this.subject.name).toEqual(this.name); | |
}); | |
describe("using theFunction", function() { | |
beforeEach(function () { | |
this.thing = theFunction('Patrick'); | |
}); | |
it("should have a new Klass", function() { | |
expect(this.thing.name).toEqual('Patrick'); | |
}); | |
}); | |
}); | |
describe("working with the spy", function() { | |
beforeEach(function() { | |
this.obj = jasmine.createSpyObj('Klass', ['name', 'properties']); | |
spyOn(window, 'Klass').andReturn(this.obj); | |
this.thing = theFunction('Patrick'); | |
}); | |
it("should have be called with Patrick", function() { | |
expect(this.thing)toHaveBeenCalledWith('Patrick'); | |
}); | |
it("should have the properties defined", function() { | |
expect(this.thing.properties).toBeDefined(); | |
}); | |
}); | |
}); | |
theFunction = function(name) | |
{ | |
var k = new Klass(name); | |
return k; | |
}; | |
Klass = function(name){ | |
this.properties = {one: 1, two: 2}; | |
this.name = name; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment