chai

Check if string contains substring from a list


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.


Solution

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

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