Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  165] [ 5]  / answers: 1 / hits: 32947  / 6 Years ago, wed, july 25, 2018, 12:00:00

I have this selector in my component whose default state is '' (empty) string but when change event is fired user can select any one of the three values that is 6, 12 or 24



it(feedform testing the selector feed frequency for value of 6, 12, 24 , () => {
const addFeedForm = shallow(
<FeedForm
submitForm={() => {}}
setFeedData={() => {}}
formType=add
feedsubmit={{
status: null,
error: {
formsubmitwarning: ,
feedname: ,
feedurl: ,
feedposttype: ,
feedfrequency: ,
feedpost: ,
feedhashtag: ,
formloginid:
}
}}
/>
);
expect(addFeedForm.state().feedfrequency).toEqual();
addFeedForm.simulate(change);
expect(addFeedForm.state().feedfrequency).toEqual(6 || 12 || 24);
});


Now while writing unit test cases for this I quickly went through Jest documentation to find matcher for any one of the three value but found no matcher that does that.



I even tried using || (or) operator in toEqual and toBe matcher but as you guessed it didn't work. Is there a way to make it work or should I skip the test all together?



Note: I am using Enzyme with Jest


More From » reactjs

 Answers
2

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)

[#53886] Monday, July 23, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
christianu

Total Points: 481
Total Questions: 124
Total Answers: 99

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
;