无法在 Jasmine 中调用 Javascript 函数
Can't Call Javascript Function in Jasmine
我是 Javascript 的新人,第一次开始。我正在尝试使用 Jasmine 来测试对象及其方法。我有以下代码:
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);
});
});
Cool it should work 的测试给了我“[object Object] is not a function on the line value = monkey.goteam(); 我花了一个小时阅读教程和搜索,但已经干涸了无论我尝试什么。非常感谢任何帮助。
this.goTeam
应声明为 function
,而不是 new function
。 new
关键字在这里不是必需的。
我是 Javascript 的新人,第一次开始。我正在尝试使用 Jasmine 来测试对象及其方法。我有以下代码:
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);
});
});
Cool it should work 的测试给了我“[object Object] is not a function on the line value = monkey.goteam(); 我花了一个小时阅读教程和搜索,但已经干涸了无论我尝试什么。非常感谢任何帮助。
this.goTeam
应声明为 function
,而不是 new function
。 new
关键字在这里不是必需的。