chai-exclude icon indicating copy to clipboard operation
chai-exclude copied to clipboard

Added support to exclude nested keys

Open buksy90 opened this issue 3 years ago • 2 comments

Hello,

I like your plugin, but I'm missing a way to define nested keys that I would like to be excluded from deep.equal() comparison.

What do you think about the change? Could you approve it?

buksy90 avatar Jul 12 '22 20:07 buksy90

Hello @buksy90, thank you for putting an effort to create the PR. I haven't gone through your code yet but did look at the tests and I was thinking if this is even necessary?

Why would you not assert the nested key separately and still use excludingEvery?

For example,

const { a: actual }  = { a: { a1: 'a1', a2: 'a2' }, b: 'b', c: 'c' }
const expected = { a2: 'a2' }

assert.deepEqualExcludingEvery(actual, expected, 'a1')

// Or you can assert the same object with a1 in it but will be excluded from comparison
assert.deepEqualExcludingEvery(actual, actual, 'a1')

mesaugat avatar Jul 15 '22 09:07 mesaugat

Hi, I have some communication service that sends and receives messages, I need to assert that message has correct format. There are multiple message types supported and so I have multiple tests. I'm using before() hook to setup the instance and then use that instance in every test. Every message contains id and that id depends on the order of message.

I would like to have my tests independent from the order of execution plus I dont really care about the message id in these tests, so I would like to use nested key to ignore this property.

But I cannot use *excludingEvery because message data can contain some other structures with id properties.

here is an example of my message structure

interface Message<T> {
  type: MessageType,
  messageKey: { id: string, initiatior: string },
  data: T
  ...
}

Did I answer your question?

buksy90 avatar Jul 17 '22 10:07 buksy90