如何使用 "toHaveBeenCalledWith" 在 Jasmine 中断言布尔值

how can I assert boolean in Jasmine using "toHaveBeenCalledWith"

我正在尝试断言一个函数被调用:

expect(functionA).toHaveBeenCalledWith(xxx, yyyy, true);

我不关心xxx和yyyy是什么,我只关心最后一个参数是否为真。

如何在 Jasmine 中实现?我试过了:

expect(functionA).toHaveBeenCalledWith(jasmine.objectContaining(true));

虽然 true 不是对象。

我也试过:

expect(functionA.calls.mostRecent().args[2]).toMatch(true);

但它给我错误:

Error:<toMatch>:Expected is not a String or a RegExp

我该如何断言?我是 Jasmine 的新手,谢谢!

假设 xxx 和 yyyy 是字符串,你可以这样做:

expect(functionA).toHaveBeenCalledWith(jasmine.any(String), jasmine.any(String), true);

另请参阅文档:official docs