Skip to content

Instantly share code, notes, and snippets.

@timwingfield
Created August 22, 2012 16:35
Show Gist options
  • Save timwingfield/3427271 to your computer and use it in GitHub Desktop.
Save timwingfield/3427271 to your computer and use it in GitHub Desktop.
constructor spying spike
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