Using test.each in Jest, I'd like to pass in a Boolean that toggles whether I expect something or not.
This is the type of repetitive code I'm trying to avoid:
if (expectFoo) {
expect(anObject).toContainEqual(
expect.objectContaining({
name: "foo"
})
);
} else {
expect(anObject).not.toContainEqual(
expect.objectContaining({
name: "foo"
})
);
}
Here is some pseudocode that illustrates my preferred (cleaner, shorter) approach:
expect(anObject).yesOrNo(expectFoo).toContainEqual(
expect.objectContaining({
name: "foo"
})
);
Is there anything like this in Jest?