utils.ts
utils.ts overview
Section titled “utils.ts overview”Provides assertion helpers used by @effect/vitest tests.
This module defines small assertion functions built on Node’s assert,
Vitest’s instance checks, and Effect’s equality support. The helpers cover
basic equality, thrown errors, defined and undefined values, strings, regular
expressions, class instances, Option, Result, and Exit. Most helpers are
synchronous; throwsAsync handles rejected promises.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”testing
Section titled “testing”assertDefined
Section titled “assertDefined”Asserts that a is not undefined.
Signature
declare const assertDefined: <A>(a: A | undefined, ..._: Array<never>) => asserts a is Exclude<A, undefined>Since v4.0.0
assertEquals
Section titled “assertEquals”Asserts that actual is equal to expected using the Equal.equals trait.
Signature
declare const assertEquals: <A>(actual: A, expected: A, message?: string, ..._: Array<never>) => voidSince v4.0.0
assertExitFailure
Section titled “assertExitFailure”Asserts that exit is a failure with a cause equal to expected.
Signature
declare const assertExitFailure: <A, E>( exit: Exit.Exit<A, E>, expected: Cause.Cause<E>, ..._: Array<never>) => asserts exit is Exit.Failure<never, E>Since v4.0.0
assertExitSuccess
Section titled “assertExitSuccess”Asserts that exit is a success with a value equal to expected.
Signature
declare const assertExitSuccess: <A, E>( exit: Exit.Exit<A, E>, expected: A, ..._: Array<never>) => asserts exit is Exit.Success<A, never>Since v4.0.0
assertFailure
Section titled “assertFailure”Asserts that result is Failure and contains an error equal to expected.
Signature
declare const assertFailure: <A, E>( result: Result.Result<A, E>, expected: E, ..._: Array<never>) => asserts result is Result.Failure<never, E>Since v4.0.0
assertFalse
Section titled “assertFalse”Asserts that self is false.
Signature
declare const assertFalse: (self: boolean, message?: string, ..._: Array<never>) => voidSince v4.0.0
assertInclude
Section titled “assertInclude”Asserts that actual includes expected.
Signature
declare const assertInclude: (actual: string | undefined, expected: string, ..._: Array<never>) => voidSince v4.0.0
assertInstanceOf
Section titled “assertInstanceOf”Asserts that value is an instance of constructor.
Signature
declare const assertInstanceOf: <C extends abstract new (...args: any) => any>( value: unknown, constructor: C, message?: string, ..._: Array<never>) => asserts value is InstanceType<C>Since v4.0.0
assertMatch
Section titled “assertMatch”Asserts that actual matches regExp.
Signature
declare const assertMatch: (actual: string, regExp: RegExp, ..._: Array<never>) => voidSince v4.0.0
assertNone
Section titled “assertNone”Asserts that option is None.
Signature
declare const assertNone: <A>(option: Option.Option<A>, ..._: Array<never>) => asserts option is Option.None<never>Since v4.0.0
assertSome
Section titled “assertSome”Asserts that option is Some and contains a value equal to expected.
Signature
declare const assertSome: <A>( option: Option.Option<A>, expected: A, ..._: Array<never>) => asserts option is Option.Some<A>Since v4.0.0
assertSuccess
Section titled “assertSuccess”Asserts that result is Success and contains a value equal to expected.
Signature
declare const assertSuccess: <A, E>( result: Result.Result<A, E>, expected: A, ..._: Array<never>) => asserts result is Result.Success<A, never>Since v4.0.0
assertTrue
Section titled “assertTrue”Asserts that self is true.
Signature
declare const assertTrue: (self: unknown, message?: string, ..._: Array<never>) => asserts selfSince v4.0.0
assertUndefined
Section titled “assertUndefined”Asserts that a is undefined.
Signature
declare const assertUndefined: <A>(a: A | undefined, ..._: Array<never>) => asserts a is undefinedSince v4.0.0
deepStrictEqual
Section titled “deepStrictEqual”Asserts that actual is deeply strictly equal to expected using Node’s assert.deepStrictEqual.
Signature
declare const deepStrictEqual: <A>(actual: A, expected: A, message?: string, ..._: Array<never>) => voidSince v4.0.0
doesNotThrow
Section titled “doesNotThrow”Asserts that thunk does not throw an error.
Signature
declare const doesNotThrow: (thunk: () => void, message?: string, ..._: Array<never>) => voidSince v4.0.0
Fails the current test with the provided error message.
Signature
declare const fail: (message: string) => voidSince v4.0.0
notDeepStrictEqual
Section titled “notDeepStrictEqual”Asserts that actual is not deeply strictly equal to expected using Node’s assert.notDeepStrictEqual.
Signature
declare const notDeepStrictEqual: <A>(actual: A, expected: A, message?: string, ..._: Array<never>) => voidSince v4.0.0
strictEqual
Section titled “strictEqual”Asserts that actual is strictly equal to expected using Node’s assert.strictEqual.
Signature
declare const strictEqual: <A>(actual: A, expected: A, message?: string, ..._: Array<never>) => voidSince v4.0.0
throws
Section titled “throws”Asserts that thunk throws, optionally checking the thrown value against an expected Error or validation function.
Signature
declare const throws: (thunk: () => void, error?: Error | ((u: unknown) => undefined), ..._: Array<never>) => voidSince v4.0.0
throwsAsync
Section titled “throwsAsync”Asserts that thunk throws or returns a rejected promise, optionally checking the failure value against an expected Error or validation function.
Signature
declare const throwsAsync: ( thunk: () => Promise<void>, error?: Error | ((u: unknown) => undefined), ..._: Array<never>) => Promise<void>Since v4.0.0