Skip to content
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

snapshot serializer fails to serialize invalid dates #6631

Closed
huafu opened this issue Jul 5, 2018 · 5 comments
Closed

snapshot serializer fails to serialize invalid dates #6631

huafu opened this issue Jul 5, 2018 · 5 comments
Labels

Comments

@huafu
Copy link
Contributor

huafu commented Jul 5, 2018

🐛 Bug Report

expect(new Date(NaN)).toMatchSnapshot()
// will throw a RangeError: Invalid time value
//        at Date.toISOString (<anonymous>)

To Reproduce

Create a simple test with the code above

Expected behavior

Even if it sounds weird to expect a date to be invalid, it shouldn't fail to create a snapshot with an invalid one. It should serialize it as invalid-date for example (NOT NaN since we need to know that it's a date type in the snapshot).

As an example of use, I experienced this while creating tests for a serializer/deserializer where I needed to save and restore invalid dates...

Link to repl or repo (highly encouraged)

https://github.com/huafu/jest-issue-demo

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.5
    CPU: x64 Intel(R) Core(TM) i5-4288U CPU @ 2.60GHz
  Binaries:
    Node: 10.4.0 - ~/.nvm/versions/node/v10.4.0/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 6.1.0 - ~/.nvm/versions/node/v10.4.0/bin/npm
  npmPackages:
    jest: ^23.3.0 => 23.3.0
@SimenB
Copy link
Member

SimenB commented Jul 5, 2018

@huafu
Copy link
Contributor Author

huafu commented Jul 5, 2018

Ok will do now, since I've already did a custom serializer for that in my project...

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants