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.
With plain Chai (no additional plugins), you can use match
:
expect(thatSelectedItem).to.match(/(?:jpg|png|gif)/)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With