Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  138] [ 3]  / answers: 1 / hits: 57802  / 5 Years ago, tue, september 17, 2019, 12:00:00

I would like to check if a string contains 'abc' or 'cde' with jest.



const substr1 = 'abc'
const substr2 = 'cde'
const str = 'ooocdeooo'


I am using



expect(str).toContain(substr1);


for one string but I cant find a clean way to check whether substr1 or substr2 is in str
How could I do that ?
Thanks !


More From » jestjs

 Answers
64

You can use a regexp with toMatch



like :



expect(str).toMatch(/(abc|cde)/i)

[#51651] Sunday, September 8, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ira

Total Points: 298
Total Questions: 112
Total Answers: 103

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
;