我正在测试一个带有两个参数的函数:一个字符串和一个数组。传递的数组必须与预期的数组完全匹配。
我试过了:
CompletableFuture<Void> cf1 = CompletableFuture.runAsync(() -> a());
CompletableFuture<Void> cf2 = CompletableFuture.runAsync(() -> b());
CompletableFuture<Void> cf3 = CompletableFuture.anyOf(cf1, cf2).thenRunAsync(() -> c());
和
expect(context.commit).toHaveBeenCalledWith('loadMunicipalityIDArray', muniIDArray)
但两个都分别给我错误:
expect(context.commit).toHaveBeenCalledWith('loadMunicipalityIDArray', expect.arrayContaining(
muniIDArray
))
和
Expected mock function to have been called with:
[501, 556, 599, 606, 622, 1783, 1842] as argument 2, but it was called with [501, 556, 599, 606, 622, 1783, 1842].
为什么考试不通过?
答案 0 :(得分:0)
好的,我是个白痴。该名称暗示该函数期待一个数组,但在实际代码中它被传递了一个集合。 老实说,Jest本来可以提供更多信息,而且我没有写出原始功能,所以我觉得责任不完全是我自己的。 无论如何,这解决了它:
let idSet = new Set(muniIDArray)
expect(context.commit).toHaveBeenCalledWith('loadMunicipalityIDArray', idSet)
我现在也将更改功能名称。