我有两个对象已被 Jasmine 设置为间谍:
spyOn(obj, 'spy1');
spyOn(obj, 'spy2');
我需要验证调用spy1
在致电之前来spy2
。我可以检查它们是否都被调用:
expect(obj.spy1).toHaveBeenCalled();
expect(obj.spy2).toHaveBeenCalled();
但这会过去即使obj.spy2()
首先被叫到。有没有一种简单的方法可以验证一个在另一个之前被调用?
看起来茉莉花人看到了这篇文章或其他类似的文章,因为该功能存在 https://jasmine.github.io/api/2.8/matchers.html#toHaveBeenCalledBefore。我不确定它已经存在了多久——他们所有 2.6 版本的 API 文档都提到了它,尽管他们存档的旧样式文档都没有提到它。
之前已被调用(expected
)
expect https://jasmine.github.io/api/2.8/global.html#expect实际值(aSpy https://jasmine.github.io/api/2.8/Spy.html) 在另一个之前被调用Spy https://jasmine.github.io/api/2.8/Spy.html.
参数:
Name Type Description
expected Spy Spy that should have been called after the actual Spy.
你的例子的失败看起来像Expected spy spy1 to have been called before spy spy2
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)