I want to write a NodeJS chai test which checks that the result of some service-call (which is an array) contains an object which is equal to what I expect. There might be some more fields in the result which I don't want to check.
There are two chai plugins which can solve this problem: chai-things (which allows you to use a syntax like expect(i).to.include.something.that.deep.equals
) and chai-like (which allows you to use a syntax like expect(i).to.be.like
).
But, in combination they don't work.
See this minimal working example:
const chai = require('chai')
const expect = chai.expect
chai.use(require('chai-things'))
chai.use(require('chai-like'))
describe('the chai setup', function() {
it('should work', function(done) {
const i = [{
name: 'Name A',
age: 1
}, {
name: 'Name B',
age: 2
}]
// Works
expect(i).to.include.something.that.deep.equals({
name: 'Name B',
age: 2
})
// Works
expect(i[1]).to.be.like({
name: 'Name B'
})
// Doesn't work
expect(i).to.include.something.that.like({
name: 'Name B'
})
done()
})
})
This doesn't work and throws an error message:
AssertionError: expected { name: 'Name B', age: 2 } to like { name: 'Name B' }
How can this be fixed?