-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
[Bug]: Storybook test, toHaveBeenCalledWith with Date arguments #30503
Comments
@blvdmitry Have you tried this? expect(args.handleChange).toHaveBeenCalledWith({ value: new Date(2020, 0, 1).toISOString() }); Dates get serialized like that so that they can be sent as a ChannelMessage to the Storybook manager. If this doesn't work, I suspect that what you're seeing printed is just the serialized version, while in fact the value is a Date object. It may simply be considered non-matching because you're comparing two Date objects, which have a different identity (despite having the same value, they aren't equal). Not sure if that's how |
I've addressed the |
@blvdmitry While trying to reproduce this bug, we found an apparent bug in your code. <Calendar defaultMonth={new Date(2020, 0, 1)} onChange={() => args.handleChange()} /> I think you'll want this instead: <Calendar defaultMonth={new Date(2020, 0, 1)} onChange={args.handleChange} /> |
Describe the bug
I'm trying to migrate to a setup using only Storybook test instead of working with Jest/Vitest directly. When testing a calendar change handler, I found that Storybook is crashing when checking for the Date arguments matching.
Here is a story I wrote:
This line is causing the issue and if I remove it the rest of the test is working fine:
The error I see in the console when this line is present:
I've also checked that changing it to new Date(...).toString() removes that e.split error and returns a correct assertion error since it's not matching the real Date argument anymore
Reproduction link
...
Reproduction steps
I will try to create a standalone reproduction link due to limited amount of time I have while working on this project but I can give access to my private repository branch with the storybook test setup for reproduction.
System
Additional context
No response
The text was updated successfully, but these errors were encountered: