5

我似乎无法在网上找到解决方案。

这是一个代码示例,因此您会遇到问题:

// Spy on the wanted function
spyOn(object, 'myFunction');

// Call it 3 times with different parameters
object.myFunction('');
object.myFunction('', 0);
object.myFunction('', 0, true);

// Now all of these expects work
expect(object.myFunction).toHaveBeenCalledTimes(3);
expect(object.myFunction).toHaveBeenCalledWith('', 0);
expect(object.myFunction).toHaveBeenCalledWith('');
expect(object.myFunction).toHaveBeenCalledWith('', 0, true);

我想测试是否正确拨打了每个电话。有没有办法说这样的话?

expect(object.myFunction).nthCall(2).toHaveBeenCalledWith('', 0, true);

???

4

1 回答 1

7

calls属性,你可以像这样使用: expect(object.myFunction.calls.argsFor(2)).toEqual(['', 0, true])

于 2018-01-11T15:15:34.377 回答