jest-matcher-deep-close-to icon indicating copy to clipboard operation
jest-matcher-deep-close-to copied to clipboard

Allow comparison of functions

Open FaisalST32 opened this issue 3 years ago • 4 comments

The test currently fails if a function type is encountered in the nested object. This can become troublesome when we're comparing objects that contain class instances with those instances containing function definitions as well.

Can we add logic to compare functions using strict equality? I could create a PR for this if needed.

FaisalST32 avatar Jan 25 '22 05:01 FaisalST32

Hello, how will you compare functions? It really feels out of the scope of this project. Maybe if you share an example I could understand more your needs

maasencioh avatar Jan 26 '22 09:01 maasencioh

Hey, thanks for getting back. Comparison of functions becomes an issue when dealing with class instances. In the screenshots below, you can see that the test fails when using toBeDeepCloseTo but passes when using toEqual. image

image

Jest uses strict equality while comparing functions, and I think this library should too.

I have already made the necessary changes, please let me know if you want me to create a PR.

FaisalST32 avatar Jan 27 '22 04:01 FaisalST32

The problem in a class is that you will compare all the properties or only the numeric ones? As my concern the idea of this package is to extend the toBeCloseTo matcher, that's why I think that if you have a class with 2 properties to be compared to is better to manually compare them.

If you still think that this changes belongs to this repo, you can create a PR and we discuss how to make it work for all of us.

maasencioh avatar Jan 31 '22 13:01 maasencioh

I have created a PR #38

FaisalST32 avatar Feb 03 '22 07:02 FaisalST32