I’m attempting to assert a partial match for a function that has been called:
let values = ["100", "200"];
setValues({
values,
name: "foo",
});
I want to assert that setValues
was called with an object containing values
and that the array contains "100"
.
I do not care about "200"
being in the array, and I do not care about name: "foo"
being in the object. I only want to assert on the "100"
value.
I have written a unit test assertion utilising objectContaining
and arrayContaining
thinking this would be correct:
expect(setValues).toHaveBeenCalledWith(
expect.objectContaining({
values: expect.arrayContaining(["100"]),
})
);
However the test does not pass, as it asserts the other values that are also called – the ones I don’t care about.
Expected: ObjectContaining {"values": ["100"]}
Received: {"values": ["100", "200"], "name": "foo"}
Where am I going wrong here in regards to the partial match?