Socket
Socket
Sign inDemoInstall

mockdate

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockdate

A JavaScript mock Date object that can be used to change when "now" is.


Version published
Weekly downloads
1.1M
decreased by-23.74%
Maintainers
1
Weekly downloads
 
Created

What is mockdate?

The mockdate npm package is designed for testing JavaScript code that relies on dates. It allows developers to temporarily 'mock' or 'fake' the current date and time, making it possible to simulate specific temporal conditions in tests without altering the system's actual clock. This is particularly useful for ensuring consistent test results and for testing time-sensitive code paths.

What are mockdate's main functionalities?

Set a mock date

This feature allows you to set the current date and time to a specific value. It's useful for testing how your application behaves on specific dates and times.

MockDate.set('2023-04-01T00:00:00.000Z');

Reset to the system's current date

After setting a mock date, you can use this feature to reset the system's date and time back to its real current value. This is particularly useful to clean up after tests that require mocking the date.

MockDate.reset();

Set a mock date with a specific timezone offset

In addition to setting a mock date, you can specify a timezone offset in minutes. This allows for more precise control over the mocked date and time, accommodating tests that are sensitive to timezones.

MockDate.set('2023-04-01T00:00:00.000Z', 120);

Other packages similar to mockdate

Keywords

FAQs

Package last updated on 25 Mar 2021

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc