`toStrictEqual` should not compare return value of `get` function
See original GitHub issuelet a = 0;
class Foo {
get foo(): i32 {
return ++a;
}
}
expect(new Foo()).toStrictEqual(new Foo());
[Actual]: Foo {
foo: 3
}
[Expected]: Foo {
foo: 4
}
It not only compares, but also produces side effects.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Expect - Jest
This is a deep-equality function that will return true if two objects have the same values (recursively). this.expand . A boolean to let...
Read more >toStrictEqual fails to distinguish 0 from 5e-324 #7941 - GitHub
Be careful about Date objects because they needs value comparison instead of object identity. While we are looking at it, can you take...
Read more >Testing anonymous function equality with Jest - Stack Overflow
toBe(expected) Expected value to be (using ===): [Function anonymous] Received: [Function anonymous] Difference: Compared values have no visual ...
Read more >Jest Expect - w3resource
The expect function is used whenever you want to test a value. ... but the error messages that you get on failing tests...
Read more >Frontend Testing with Jest - Assertions deep dive
Discover how you can write clever Javascript unit tests with the Jest ... identity of values, while toEqual does a deep comparison of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Steps to prove this:
expect(someRef).toStrictEqual(anotherRef)
get
property function onsomeRef
is executed.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:
Well, I got it