Skip to content

⏳ Programmatically step through asynchronous code during test ⏳

License

Notifications You must be signed in to change notification settings

marcellomontemagno/parcae

Repository files navigation

Actions Status

parcae
parcae
Programmatically step through asynchronous code during test

Introduction

parcae is a tiny utility allowing you to programmatically step through asynchronous code during test.

Some example where parcae can be handy:

  • Test complex loading state on a user interface
  • Reproduce race conditions
  • Test any function containing non-trivial asynchronous logic

Installation

npm install --save parcae

import createFutures from "parcae"

How to use

Initialize the utility

const futures = createFutures()

mock the asynchronous functions you want to control making them return

futures.predict("aKey")

make a function resolve and await for it by invoking

await futures.resolve("aKey", aResult)

otherwise, make a function reject and await for it by invoking

await futures.reject("aKey", anError)

Examples

Basic example

UI example

About

⏳ Programmatically step through asynchronous code during test ⏳

Resources

License

Stars

Watchers

Forks

Packages

No packages published