Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tapjs/clock

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tapjs/clock

a make believe clock for tests involving time

  • 1.1.31
  • npm
  • Socket score

Version published
Weekly downloads
359
decreased by-26.43%
Maintainers
2
Weekly downloads
 
Created
Source

@tapjs/clock

A deterministic mock clock for use in tests involving time.

A mock clock will be available at t.clock. If you call t.clock.enter(), it will monkey-patch all the globals to be tied to the deterministic mock clock implementation. When the test completes, the patched globals will return to their previous state automatically.

USAGE

Add the plugin by running:

tap plugin add @tapjs/clock

Then, you can use it by accessing the t.clock object on any test, which is an instance of the Clock class.

For example:

t.test('some timers and such', async t => {
  t.clock.enter()
  let timeoutFired = false
  setTimeout(() => (timeoutFired = true), 100)
  t.clock.advance(50)
  t.equal(timeoutFired, false)
  t.clock.advance(50)
  t.equal(timeoutFired, true)
})

If you aren't using the @tapjs/after plugin, then you'll have to call t.clock.exit() at some point to restore the global timers to their previous states if you enter it.

See clock-mock for full API details.

Keywords

FAQs

Package last updated on 11 Jun 2024

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