Chai.js - Check if string contains substring from a list

userMod2 picture userMod2 · Jul 11, 2017 · Viewed 9.6k times · Source

I'm using chai.js writing some automation tests. I have a string:

url(http://somewhere.com/images/myimage.png)

I want to do something like:

expect(thatSelectedItem).contains.any('jpg', 'png', 'gif')

However can't seem to find anything in chai.js

Any have any suggestions - read the page http://chaijs.com/api/bdd/ however no luck.

Any help appreciated.

Thanks.

Answer

robertklep picture robertklep · Jul 11, 2017

With plain Chai (no additional plugins), you can use match:

expect(thatSelectedItem).to.match(/(?:jpg|png|gif)/)