5 javascript expectations jasmine
我似乎无法在网上找到解决方案。
这是一个代码示例,因此您会遇到问题:
// 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);
Run Code Online (Sandbox Code Playgroud)
我想测试是否每次调用都正确。有没有办法说这样的话?
expect(object.myFunction).nthCall(2).toHaveBeenCalledWith('', 0, true);
Run Code Online (Sandbox Code Playgroud)
???
有calls属性,你可以像使用:
expect(object.myFunction.calls.argsFor(2)).toEqual(['', 0, true])
| 归档时间: |
|
| 查看次数: |
4554 次 |
| 最近记录: |