Socket
Book a DemoInstallSign in
Socket

jest-serializer-date

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-serializer-date

Jest snapshot serializer to remove annoying Date object inconsistencies

1.0.2
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

A Jest snapshot serializer that removes headaches when working with JavaScript Date objects

NPM version Build Status

When encountering a JavaScript Date object within a Jest snapshot, this serializer determines if the date corresponds to the current date (new Date()) or not. It then serializes them as follows:

Current Date:

- "yourDate": 2018-07-13T22:42:46.531Z
+ "yourDate": "Current Date"

Non-current Date:

- "yourDate": 2018-07-13T22:42:46.531Z
+ "yourDate": "07-13-2018"

This effectively avoids errors where snapshots fail because

  • Something like new Date() was used, and the snapshot test was re-run on a different date
  • The snapshot test is run in an environment with a different timezone than that of the developer who wrote the test, causing date serialization mis-match

Install

Install the package as a dev-dependency:

# npm
npm install --save-dev jest-serializer-date

# yarn
yarn add --dev jest-serializer-date

Tell jest to use the package in package.json:

"jest": {
    "snapshotSerializers": ["jest-serializer-date"]
}

FAQs

Package last updated on 13 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.