@ccorcos/test-clock
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Test Clock

A clock for testing async code without actually having to wait.

Getting Started

npm install @ccorcos/test-clock
const { sleep, run } = new TestClock()
const log = []

const promises = [
	(async () => {
		await sleep(1)
		log.push(1)
	})(),
	(async () => {
		log.push(0)
		await sleep(10)
		log.push(10)
	})(),
	(async () => {
		await sleep(4)
		log.push(4)
		await sleep(10)
		log.push(14)
		await sleep(10)
		log.push(24)
	})(),
	(async () => {
		await sleep(5)
		log.push(5)
		await sleep(10)
		log.push(15)
		await sleep(10)
		log.push(25)
	})(),
]

await run()
await Promise.all(promises)

assert.deepEqual(log, [0, 1, 4, 5, 10, 14, 15, 24, 25])

Readme

Keywords

none

Package Sidebar

Install

npm i @ccorcos/test-clock

Weekly Downloads

3

Version

0.0.5

License

MIT

Unpacked Size

6.91 kB

Total Files

11

Last publish

Collaborators

  • ccorcos