I am trying to write a test that checks if a Constructor function used the .call() function on another function. Here is an example:
Code To Test:
function Mammal(name, color) {
this.name = name;
this.color = color;
};
Mammal.prototype.beep = function() {
return "Arf, Arf"
};
Mammal.prototype.changeColor = function() {
this.color = "brown"
};
// TEST IF MAMMAL.CALL WAS USED IN THE DOG CONSTRUCTOR
function Dog(name, color){
Mammal.call(this,name, color);
}
Current Test (Doesn't Work Properly:
describe("Dog Class", function(){
beforeEach(function(){
dog = new Dog("Stewie", "Red");
});
it("should have a Name and Mammal color in its constructor", function(){
expect(dog.color).toEqual("Red");
expect(truck.name).toEqual("Stewie");
});
it("should be called with the Mammal Constructor", function(){
var test = spyOn(window, "Mammal").andCallThrough();
expect(test.wasCalled).toEqual(true);
});
});
I have referred to this post and similar posts, but many of them provide examples setting up tests with method calls on Object Literals. ".call" would be a Function for Function objects.
My current test doesn't change the wasCalled property to "true" even though Mammal.call() is being invoked in the Dog constructor function. How can I set up my test to check that Mammal.call() was used in the Dog Constructor?