UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

32 lines (31 loc) 1.13 kB
import { expect } from "bun:test"; import { getIdentifiers } from "../util/item.js"; /** Expect that an object matches `PromiseLike` */ export const EXPECT_PROMISELIKE = expect.objectContaining({ // biome-ignore lint/suspicious/noThenProperty: On purpose. then: expect.any(Function), }); /** Expect `Item` objects with an `.id` prop in any order. */ export function expectUnorderedItems(items, keys) { try { expect(items).toBeInstanceOf(Object); expect(Array.from(getIdentifiers(items)).sort()).toEqual(Array.from(keys).sort()); } catch (thrown) { if (thrown instanceof Error) Error.captureStackTrace(thrown, expectUnorderedItems); throw thrown; } } /** Expect `Item` objects with an `.id` prop in a specified order. */ export function expectOrderedItems(items, keys) { try { expect(items).toBeInstanceOf(Object); expect(Array.from(getIdentifiers(items))).toEqual(Array.from(keys)); } catch (thrown) { if (thrown instanceof Error) Error.captureStackTrace(thrown, expectOrderedItems); throw thrown; } }