You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently switched from Jest to Vitest and very often in Jest I would use the .toBe() instead of .toEqual() since I never remember which one is which and in Jest when we do use the wrong one then we have a great useful message telling us that we probably meant to use another validity check. This is very helpful but in Vitest it just fails equality check without giving us any hint at all.
For example, if we have this test that we run in both libs
in Jest we have this helpful message "serializes to the same string" and also other suggestions
expect(received).toBe(expected) // Object.is equality
If it should pass with deep equality, replace "toBe" with "toStrictEqual"
Expected: [{"age": 30, "id": 123, "name": "John"}]
Received: serializes to the same string
at Object.<anonymous> (/src/index.spec.ts:34:50)
but in Vitest, it just fails without providing any hint of our problem
FAIL src/index.spec.ts > My Test Suite > should have the same array
AssertionError: expected [ { id: 123, name: 'John', age: 30 } ] to be [ { id: 123, name: 'John', age: 30 } ] // Object.is equality
❯ src/stores/__tests__/viewStore.spec.ts:63:49
61| expect(store.selectedTab).toBe('compId');
62|
63| expect([{ id: 123, name: 'John', age: 30 }]).toBe([{ id: 123, name: 'John', age: 30 }]);| ^
64| });
65| });
A new developer using Vitest will most certainly be confused and won't know why it failed, then do a search on Google or Stack Overflow. However in Jest, it gives us a great hint of how to modify our code and use the correct check. Half of the time I use the wrong one, so I will very often see this failing... to be or not to be 😄
Suggested solution
Use the same message as Jest which helps user finding the issue with the test. The message that always remind me that I used the wrong check is
Received: serializes to the same string
then I know right away that I must use .toEqual() instead of .toBe()
A very simple message that can so so helpful
Alternative
No response
Additional context
I ran the same test with both libs at latest versions, Jest 28 and Vitest 0.12.4
Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
The text was updated successfully, but these errors were encountered:
ghiscoding
changed the title
deep equality check failing message is not helpful enough
deep equality check failing message is very different compare to Jest
May 12, 2022
chaii3
pushed a commit
to chaii3/vitest
that referenced
this issue
May 13, 2022
Clear and concise description of the problem
I recently switched from Jest to Vitest and very often in Jest I would use the
.toBe()
instead of.toEqual()
since I never remember which one is which and in Jest when we do use the wrong one then we have a great useful message telling us that we probably meant to use another validity check. This is very helpful but in Vitest it just fails equality check without giving us any hint at all.For example, if we have this test that we run in both libs
in Jest we have this helpful message "serializes to the same string" and also other suggestions
but in Vitest, it just fails without providing any hint of our problem
A new developer using Vitest will most certainly be confused and won't know why it failed, then do a search on Google or Stack Overflow. However in Jest, it gives us a great hint of how to modify our code and use the correct check. Half of the time I use the wrong one, so I will very often see this failing... to be or not to be 😄
Suggested solution
Use the same message as Jest which helps user finding the issue with the test. The message that always remind me that I used the wrong check is
then I know right away that I must use
.toEqual()
instead of.toBe()
A very simple message that can so so helpful
Alternative
No response
Additional context
I ran the same test with both libs at latest versions, Jest 28 and Vitest
0.12.4
Validations
The text was updated successfully, but these errors were encountered: