问题描述
我有两个被设置为Jasmine间谍的对象:
I've got two objects that have been set up as spies with Jasmine:
spyOn(obj, 'spy1');
spyOn(obj, 'spy2');
我需要验证对 spy1的调用
在调用 spy2
之前来。我可以检查它们是否都被调用:
I need to verify that calls to spy1
come before calls to spy2
. I can check if both of them are called:
expect(obj.spy1).toHaveBeenCalled();
expect(obj.spy2).toHaveBeenCalled();
但即使 obj.spy2()$ c,这也会通过首先调用$ c>。是否有一种简单的方法可以验证一个人是否在另一个之前被调用?
but this will pass even if obj.spy2()
was called first. Is there an easy way of verifying that one was called before the other?
推荐答案
看起来茉莉花的人看过这篇帖子或其他人喜欢它,因为。我不知道它已经存在了多长时间 - 所有的API文档都回到2.6提到它,尽管他们的档案旧版文档都没有提到它。
Looks like the Jasmine folks saw this post or others like it, because this functionality exists. I'm not sure how long it's been around -- all of their API docs back to 2.6 mention it, though none of their archived older style docs mention it.
参数:
Name Type Description
expected Spy Spy that should have been called after the actual Spy.
您示例的失败似乎是在间谍spy2之前调用了预期的间谍spy1
。
这篇关于有没有办法用Jasmine来验证间谍执行的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!