【发布时间】:2018-02-20 11:03:43
【问题描述】:
这是测试代码
var list = new List([1, 2, 3, 4]);
var list2 = new List([5, 1]);
beforeAll(function () {
spyOn(list.values, 'map').and.callThrough();
list.map(plusOne);
});
it('Array.prototype.map()', function () {
expect(list.values.map).not.toHaveBeenCalled();
});
This results in the following error 1) List must not call native Array function Array.prototype.map() Message:
Error: <toHaveBeenCalled> : Expected a spy, but got Function.
Usage: expect(<spyObj>).toHaveBeenCalled()
class List {
constructor(clist = []) {
this.values = clist;
}
map(f) {
var temp = [];
this.values.forEach((item, index) => {
temp.push(f(item));
});
this.values = temp;
return this;
}
}
module.exports = { List };
我不认为这是一个单元测试失败,因为无论我调用 not.tohaveBeenCalled() 还是 toHaveBeenCalled(),我都会收到相同的消息。
我正在使用节点 8.9.4 和 jasmine 2.8.0。
我相信语法是正确的,因为当我针对这些测试运行其他代码时,它们通过了。但是我的代码导致了这个错误。
我的问题是上述错误是什么意思? 问候,
【问题讨论】:
标签: javascript jasmine