Jasmine-compatible TypeScript object equality library

120 Views Asked by At

Disclaimer: TypeScript (and more generally JavaScript) object equality functions have been discussed en-masse here (e.g., https://stackoverflow.com/a/63496057) and everywhere else (e.g., https://bobbyhadz.com/blog/typescript-object-comparison). I am not looking for any code snippets (there are more than enough in How to determine equality for two JavaScript objects?). There are various libraries (underscore, lodash, fast-deep-equal, fast-equal, nano-equal, etc.) for object equality checking, but it's hard to understand the differences between them.

What I miss in most questions and answers about TypeScript object equality is unit testing.
Because the testing framework decides what should be considered "equal".
I use Jasmine for unit tests, thus the toEqual(…) method governs object equality.

For example, JSON.stringify(…) is not consistent with Jasmine's toEqual(…) because JSON.stringify(…) is sensitive to property order:

JSON.stringify({a:1, b:2}) != JSON.stringify({b:2, a:1});

expect({a:1, b:2}).toEqual({b:2, a:1});

For full consistency, an equality check would have to yield the same result as Jasmine's toEqual(…) for every conceivable input.

I am aware that Jasmine supports custom equality testers, but these should only be used for special cases.

Question: Are any of the aforementioned equality libraries fully consistent with Jasmine's toEqual(…)?
If none of them are, which are the edge cases that yield different results than Jasmine?

[Edit: Rephrased the question to avoid asking for subjective advice on off-site libraries; added two more equality libraries to the list; clarified what I mean by full consistency with Jasmine.]

0

There are 0 best solutions below