【发布时间】:2021-11-21 01:25:56
【问题描述】:
我正在学习茉莉花。我无法通过考试。
下面的 it() 在 Records 的描述中,因此 Records 应该在获取错误时恢复。对于这篇文章,我将预期的 JSON 对象替换为“此处的对象”。这不是问题及其敏感数据。
我目前遇到“预期的间谍日志已被调用”失败。我认为这与运行 console.log 有关吗?但是当我插入一个console.log时,我得到了失败的'Expected spy log to not be called。所以这让我很困惑。我当然可能完全看错了。
我的代码只是一个获取,从一个名为 retrieve() 的函数返回数据。该函数正在导出,并在此处导入以用于测试。
it('should recover on fetch error', function(done){
window.path = "http://localhost:3000/recordszzz";
spyOn(console, "log").and.callFake(function(){});
function check(output) {
window.path = "http://localhost:3000/records";
expect(console.log).toHaveBeenCalled();
console.log.calls.reset();
retrieve().then(function(output){
var expected = {Object here};
expect(output).toEqual(expected);
expect(console.log).not.toHaveBeenCalled();
done();
});
}
retrieve().then(check);
【问题讨论】:
标签: javascript unit-testing jasmine