marcellomontemagno / parcae

⏳ Programmatically step through asynchronous code during test ⏳

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 ⏳

License:MIT License


Languages

Language:JavaScript 93.4%Language:Shell 5.4%Language:HTML 1.1%