alexjeffburke / chai-better-shallow-deep-equal

MIT License
3 stars 0 forks source link

Not failing comparison when expected value is undefined #6

Open jbcripe68 opened 2 years ago

jbcripe68 commented 2 years ago

I see a difference between the default chai shallow-deep-equal comparison versus this one. I would like to use undefined for a value and fail if the comparing object has any value. When I run the following code I see 'message is shallowDeepEqual to expected' but if I comment out the chai.use(better_sde) the comparison fails like I would expect. Is there a way to have this behavior using this package?

const chai = require('chai'); const expect = chai.expect; const better_sde = require('chai-better-shallow-deep-equal'); better_sde.addMatch({ leftType: 'string', rightType: 'number', handler: (lhs, rhs) => [lhs, String(rhs)] }); better_sde.addMatch({ leftType: 'number', rightType: 'string', handler: (lhs, rhs) => [String(lhs), rhs] }); chai.use(better_sde);

const message = { a: '3' } const expected = { a: undefined }

try { expect(message).shallowDeepEqual(expected); console.log('message is shallowDeepEqual to expected'); } catch(err) { console.log('message is NOT shallowDeepEqual to expected'); }

jbcripe68 commented 2 years ago

Now that I check the default chai library is throwing:

Error: Invalid Chai property: shallowDeepEqual

So I guess this better-shallow-deep-equal accepts but ignores keys with undefined as their value. Is there a way to check that a key does not exist using shallDeepEqual?