我有以下代码:
describe("Player", function() {
var player;
beforeEach(function(){
player = new Player({
name: "Mark"
});
});
it("has a name", function() {
expect(player.name).toEqual("Mark");
});
it("has a score"), function() {
expect(player.score).toEqual(0);
};
});
Jasmine 说它通过了 2 个规范,即使 player.score
是 undefined
如果我这样做...
it("has a score"), function() {
console.log("hello")
expect(player.score).toEqual(0);
};
我可以看到第二个测试从未运行过。任何想法为什么? (这是我第一次使用 Jasmine)。
最佳答案
第二个规范(it()
调用)中有一个错误的右括号。它应该是:
it("has a score", function() {
expect(player.score).toEqual(0);
});
我经常遇到这个问题:Jasmine 规范中的语法错误导致测试甚至没有运行,而不是像他们应该的那样失败。 (我相信有 may be an outstanding bug against Jasmine for this 。)
关于javascript - 只有第一个测试实际在 Jasmine 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13535594/