Iterables
some(iterable, assertion)
Use some to assert that at least one value in an iterable passes the provided assertion. Throws an error if no values pass the assertion.
Returns the result of calling the assertion on the first value that passes.
import { some } from "mix-n-matchers/utilities"; const nums = [1, 2, 3]; const result = some(nums, (value) => { expect(value).toBeGreaterThan(2); return value; }); expect(result).toBe(3);
Tests
Assertion callback can be asynchronous, in which case some will return a promise that resolves to the result of calling the assertion on the first value that passes.
someAsync(asyncIterable, assertion)
Use someAsync to assert that at least one value in an asynchronous iterable passes the provided assertion. Throws an error if no values pass the assertion.
Returns a promise that resolves to the result of calling the assertion on the first value that passes.
import { someAsync } from "mix-n-matchers/utilities"; const asyncNums = async function* () { yield 1; yield 2; yield 3; }; const promise = someAsync(asyncNums(), (value) => { expect(value).toBeGreaterThan(2); return value; }); expect(promise).resolves.toBe(3);
Tests
every(iterable, assertion)
Use every to assert that every value in an iterable passes the provided assertion. Throws an error if any value fails the assertion.
Returns an array of the results of calling the assertion on each value.
import { every } from "mix-n-matchers/utilities"; const nums = [1, 2, 3]; const results = every(nums, (value) => { expect(value).toBeGreaterThan(0); return value * 2; }); expect(results).toEqual([2, 4, 6]);
Tests
Assertion callback can be asynchronous, in which case every will return a promise that resolves to an array of the results of calling the assertion on each value.
everyAsync(asyncIterable, assertion)
Use everyAsync to assert that every value in an asynchronous iterable passes the provided assertion. Throws an error if any value fails the assertion.
Returns a promise that resolves to an array of the results of calling the assertion on each value.
import { everyAsync } from "mix-n-matchers/utilities"; const asyncNums = async function* () { yield 1; yield 2; yield 3; }; const promise = everyAsync(asyncNums(), (value) => { expect(value).toBeGreaterThan(0); return value * 2; }); expect(promise).resolves.toEqual([2, 4, 6]);
Tests