I'm new at Javascript, starting for the first time. I am trying to use Jasmine to test objects and their methods. I have the following code:
function Monkey(x, y) {
this.x = x;
this.y = y;
this.goteam = new function () {
return x;
};
}
describe("Cool", function () {
it("should work", function () {
var monkey = new Monkey(1, 2);
var value = monkey.goteam();
expect(value).toBe(1);
});
});
The test Cool it should work gives me "[object Object] is not a function on the line value = monkey.goteam(); I have spent an hour reading tutorials and searching, but have come up dry no matter what I try. Any help is much appreciated.
goteamshould just be a function, notnew function() ...Pro tip: just try stuff out in the console before bothering to write a test; it excludes an entire class of issues. Creating anew Monkey(...)and looking at it would have helped clue you in.