Jest matcher to match any one of three values
The jest-extended
library provides a .toBeOneOf([members])
matcher:
it("feedform testing the selector feed frequency for value of 6, 12, 24 ", () => {
expect(addFeedForm.state().feedfrequency).toBeOneOf([6, 12, 24]);
});
There is no method on the Jest API to match multiple values.
A way to do this check is using a regex:
expect(String(addFeedForm.state().feedfrequency)).toMatch(/^6|12|24$/);
In order to one among the expected value, you can reverse the comparison and test it using toContain
method like
expect(addFeedForm.state().feedfrequency).toEqual('');
addFeedForm.simulate('change');
expect([6, 12, 24]).toContain(addFeedForm.state().feedfrequency)
Another way to achieve this is to do the comparison outside of Jest's assertion and simply expect that to be true:
expect(
addFeedForm.state().feedfrequency === 6 ||
addFeedForm.state().feedfrequency === 12 ||
addFeedForm.state().feedfrequency === 24
).toBe(true)