Skip to content
Loess

@loess/test-utils

Small helpers for tests that wait on something live, which any package or app can use. They know nothing about Loess: a helper that needs a host, a device, or a key stays in the ./test entry of the package it belongs to, such as @loess/sdk/test.

import { eventually, firstWhere } from '@loess/test-utils';
 
const feed = yield * firstWhere(moments.feed, (posts) => posts.length === 50); // the first value that passes
yield * eventually(Effect.try(() => expect(traffic.isIdle()).toBe(true))); // a check, tried again until it passes

firstWhere(stream, isWanted, within) gives the first value of a stream that passes isWanted, and fails with a timeout after within, 20 seconds unless you pass another. A wait that never ends then fails on its own line, not on the test's timeout. A latency test, whose requests wait for the trip of a deployed host, passes a longer within.

eventually(check, within) runs a check every 25 ms until it passes, and after within, 10 seconds unless you pass another, fails with the check's last failure. It is for what sync does in the background, so tests that use it run on the live clock.

Tests never sleep, as Principles says: they wait for a condition with one of these.

Place in the stack

It imports only effect, and only tests and test helpers import it.