Skip to content

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

Notifications You must be signed in to change notification settings

ccorcos/test-clock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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])

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published