E
E
Egor Dovydenko2022-01-19 14:02:11
React
Egor Dovydenko, 2022-01-19 14:02:11

How to pass multiple possible options to toEqual for react jest test?

const title = component.find('h1');
  expect(title.text()).toEqual('Text 1' || 'Test 2');


Here is an example of what I want. The type in the header component can be different: either Test 1 or T test 2 .
There can be no other options. Therefore, I want to check for both conditions. How to implement correctly? The given example is not working, it is checked only for the first text.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2022-01-19
@Doktorjd

If the title is randomly selected from two, you can reverse the condition.
In the first part, put an array with two titles, then .toContain(title.text())
https://jestjs.io/docs/expect

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question