UNPKG

@zerothrow/vitest

Version:

Vitest matchers for ZeroThrow Result types

82 lines 1.84 kB
// src/index.ts import { toBeOkMatcher, toBeOkWithMatcher, toBeErrMatcher, toBeErrWithMatcher, toHaveErrorCodeMatcher, toHaveErrorMessageMatcher } from "@zerothrow/expect"; import { expect } from "vitest"; function createVitestContext(utils) { return { equals: utils?.equals || ((a, b) => a === b) }; } function toBeOk(received) { const result = toBeOkMatcher(received, createVitestContext(this.utils)); return { pass: result.pass, message: result.message }; } function toBeOkWith(received, expected) { const result = toBeOkWithMatcher(received, expected, createVitestContext(this.utils)); return { pass: result.pass, message: result.message }; } function toBeErr(received) { const result = toBeErrMatcher(received, createVitestContext(this.utils)); return { pass: result.pass, message: result.message }; } function toBeErrWith(received, expected) { const result = toBeErrWithMatcher(received, expected, createVitestContext(this.utils)); return { pass: result.pass, message: result.message }; } function toHaveErrorCode(received, code) { const result = toHaveErrorCodeMatcher(received, code); return { pass: result.pass, message: result.message }; } function toHaveErrorMessage(received, message) { const result = toHaveErrorMessageMatcher(received, message); return { pass: result.pass, message: result.message }; } var vitestMatchers = { toBeOk, toBeOkWith, toBeErr, toBeErrWith, toHaveErrorCode, toHaveErrorMessage }; function setup() { expect.extend(vitestMatchers); } if (typeof expect !== "undefined" && typeof expect.extend === "function") { setup(); } export { setup, toBeErr, toBeErrWith, toBeOk, toBeOkWith, toHaveErrorCode, toHaveErrorMessage, vitestMatchers }; //# sourceMappingURL=index.js.map