-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toStrictEqual
should not compare return value of get
function
#344
Comments
Yes. This behavior is mirrored in jest object comparisons. It was by design. |
Can you provide a comparison without access to set/get ? Do you mean that it returns 3/4 not 1/2? |
Steps to prove this:
This behavior is by design. If you think that you truly need strict equality, I might recommend wrapping your object with a special function like this: function wrap(a: A): B {
// copy each a value you want to test to a type B
let b = new B();
b.prop1 = a.prop1;
return b;
}
expect(wrap(myA)).toStrictEqual(wrap(otherA)); |
but this is not ts. how to define the function genericly?and compare the private field |
I can't deviate from developer expectations. Perhaps make a method on the class instead? class Foo {
__asBar(): Bar {
// Make whatever you want to compare here
}
} Yes. This is not an elegant solution. Aspect happens to be very opinionated. I hope this answer suffices. |
By the way, private fields are compared. The problem is that computed fields are also compared. This is how jest currently works in production when working in a js environment. |
This is really bad, because the type deduction ability of As is much worse than that of TS. Many times a value val type is T | null, but it is not null at a certain position, so I need to cast val to T. The code for the cast is really Too much. So I wrote a get function to encapsulate the forced conversion logic, but even if it is private or not used in the unit test, this function will be called and then all panic. That is to say, the current design of as-pect affects the code implementation details of some as libraries. |
Again. This testing suite is designed with Web Developer ergonomics and expectations. You can leave this open as long as you would like. Sorry for the inconvenience. |
Well, I got it |
It not only compares, but also produces side effects.
The text was updated successfully, but these errors were encountered: