Behaviour of deep matching inconsistent between arrays and objects.
- Sinon version : master
What did you expect to happen? Both of the following to return true:
sinonMatch({ deep: { str: "sinon" } }).test({ deep: { str: "sinon", ignored: "value" } })); //true
sinonMatch([{ str: "sinon" }]).test([{ str: "sinon", ignored: "value" }])) //actual false, expected true
What actually happens
The first returns true (as expected), the second returns false.
To get the desired behaviour, the second line needs to be restated as
sinonMatch([sinonMatch({ str: "sinon" })]).test([{ str: "sinon", ignored: "value" }])) //false
i.e. explicitly nesting the matcher which seems counter intuitive.
How to reproduce
I have added some passing testcases to PR #1320 one of which (returns false if array is not equal (even if the contents would match (deep equal))) I think should be changed.
I would agree with @ashirley that having to nest matches is counter-intuitive, and the only way I was able to figure out what was going on was to see this issue and adjust my approach
On the flip side, I didn't know that you could nest matches like this until I saw this issue, and this is likely going to fix an issue that I was having
If sinonMatch encounters an expectation of type "object", it will use its own matchObject function, which only checks all the fields that are part of the expectation. If it encounters an object of type "array", it doesn't have a default handler and will instead let the expectation be handled by deepEqual, which is stricter as it checks the fields in both the expectation and the actual object.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I still think this is a valid issue, how do I prevent it as being marked stale?
I've added a "pinned" label, which tells stale bot to back off