Is it possible to assert that an array includes multiple specific items using chai?
For example, I would expect this to work:
['foo', 'bar'].should.include(['foo', 'bar'])
Instead chai throws: "expected [ 'foo', 'bar' ] to include [ 'foo', 'bar' ]"
I also tried this but it only asserts that the first item is present:
['foo', 'bar'].should.include('foo', 'bar') // variable args instead of array
What am I missing?
var assert = require('chai'). assert , foo = 'bar' , beverages = { tea: [ 'chai', 'matcha', 'oolong' ] }; assert. typeOf(foo, 'string'); // without optional message assert. typeOf(foo, 'string', 'foo is a string'); // with optional message assert.
In Chai. js, the equal assertion, along with most other included Chai assertions, uses Javascipt's strict equality. During testing, it often is the case that strict equality is not desired, but instead equality in the sense that two objects are “equivalent” in that they have the same content.
Chai is such an assertion library, which provides certain interfaces to implement assertions for any JavaScript-based framework. Chai's interfaces are broadly classified into two: TDD styles and BDD styles.
So when comparing objects, Chai will check for reference. When you use deepEqual , Chai will go down the object hierarchy and compare every value of every property. Example: const a = {"a": "a"}; const b = {"a": "a"}; expect(a).
You can use members to expect array members.
Ex:
expect(['foo', 'bar']).to.include.members(['foo', 'bar'])
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