How to assert with chai that some div('.MyDive') contains text 'Some text'?
<div class="MyDive">
<div>Some text</div>
</div>
You'll want to pull in jQuery
to access elements on the DOM. Once you have that, you can assert against DOM elements using vanilla Chai like so:
expect($('div.MyDive').text()).to.have.string('Some text');
If you want to visually clean up your code a bit, you could also pull in a plugin like chai-jquery
and use a custom assertion, such as contain(text)
:
expect($('div.MyDive')).to.contain('Some text');
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