1. @tapjs/clock
a make believe clock for tests involving time
@tapjs/clock
Package: @tapjs/clock
Last modified: Tue, 26 Mar 2024 23:27:04 GMT
Version: 1.1.20
License: BlueOak-1.0.0
Downloads: 1,631

Install

npm install @tapjs/clock
yarn add @tapjs/clock

@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.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code