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

Viewed 17753

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.

2 Answers
expect(thatSelectedItem).to.contain.oneOf(['jpg', 'png', 'gif'])

This lands with v4.3.0 (docs). oneOf can be chained with contain, contains, include and includes, which will work with both arrays and strings. It's strongly recommended to use because the error messages you get with it are much cleaner.

Related