-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Invalid Date object will throw a TypeError in Vitest #2216
Comments
I think this is chai problem. The error comes from |
@sheremet-va I'm looking at package.json but I can not see Chai as a dependency. I do not know pnpm but I do see Chai in pnpm-lock.yaml. Sorry, this might not be important. I am only trying to understand when/why Chai is injected into Vitest, in order to better understand where a fix for invalid dates should exist. I do not think it is obvious that it should be fixed in Loupe. Could you check out chaijs/loupe#58 and let us know what you think? |
Not sure how you missed it: https://github.com/vitest-dev/vitest/blob/main/packages/vitest/package.json#L111 Vitest uses chai's
Not sure what I can say 😄 Your issue is correct, I would expect it to be fixed on their side, and then we just upgrade. |
@sheremet-va This has been fixed in After some lengthy discussions (chaijs/loupe#58 (comment), chaijs/loupe#59 (comment)), we settled on const { it, expect } = import.meta.vitest
it('Invalid Date is "Invalid Date"', () => {
expect (new Date ('not a date')).toBe ('Invalid Date')
}) |
You should not get the internal error, when you call Correct check would be: expect (new Date ('not a date').valueOf()).toBe(NaN) Anyway, this issue can be closed, since Vitest 0.25.0 updated chai version to the one that has the fix. |
Describe the bug
The following two assertions should both succeed. But due to Vitest usage of
.toJSON()
onDate
objects, the second line will fail with aTypeError
.The reason is that
.toJSON()
returnsundefined
on invalid Date objects.On node 18.12 I get the following error:
On StackBlitz, I get:
Reproduction
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: