在Jasmine测试中创建间谍时,必须传递间谍名称,例如:
var spy = jasmine.createSpy('spy');
...
expect(spy).toHaveBeenCalled();
答案 0 :(得分:1)
首先,让我们做一个简单的实验(在Jasmine 2.0上测试):
it("sandbox playground", function() {
var twin1 = jasmine.createSpy('twin brother').and.returnValue({});
var twin2 = jasmine.createSpy('twin brother').and.returnValue({});
var unnamed = jasmine.createSpy(undefined).and.returnValue({});
var skipped = jasmine.createSpy().and.returnValue({});
expect(twin1).toHaveBeenCalled();
expect(twin2).toHaveBeenCalled();
expect(unnamed).toHaveBeenCalled();
expect(skipped).toHaveBeenCalled();
});
结果:
Firefox 56.0.0 (Windows 7 0.0.0) Sample Tests. sandbox playground FAILED
Expected spy twin brother to have been called.
@tests/sampleTests.spec.js:37:9
Expected spy twin brother to have been called.
@tests/sampleTests.spec.js:38:9
Expected spy unknown to have been called.
@tests/sampleTests.spec.js:39:9
Expected spy unknown to have been called.
@tests/sampleTests.spec.js:40:9
所以,回答你的问题:
正如我们所看到的,框架本身并没有对它们进行检查,所以正式上没有任何内容。
但无论如何我建议引入一些约定 你自己有可读和有意义的测试结果,以尽量减少 调试失败的测试用例的努力。