Skip to content

utils

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.

21 exports Added in v4.0.0 Source

Testing

Asserts that a is not undefined.

Signature

declare function assertDefined<A>(
  a: A | undefined,
  ..._: Array<never>
): asserts a is Exclude<A, undefined>;

assertEquals

Added in v4.0.0 Source

Asserts that actual is equal to expected using the Equal.equals trait.

Signature

declare function assertEquals<A>(
  actual: A,
  expected: A,
  message?: string,
  ..._: Array<never>
): void;

Asserts that exit is a failure with a cause equal to expected.

Signature

declare function assertExitFailure<A, E>(
  exit: Exit<A, E>,
  expected: Cause<E>,
  ..._: Array<never>
): asserts exit is Failure<never, E>;

Asserts that exit is a success with a value equal to expected.

Signature

declare function assertExitSuccess<A, E>(
  exit: Exit<A, E>,
  expected: A,
  ..._: Array<never>
): asserts exit is Success<A, never>;

Asserts that result is Failure and contains an error equal to expected.

Signature

declare function assertFailure<A, E>(
  result: Result<A, E>,
  expected: E,
  ..._: Array<never>
): asserts result is Failure<never, E>;

assertFalse

Added in v4.0.0 Source

Asserts that self is false.

Signature

declare function assertFalse(self: boolean, message?: string, ..._: Array<never>): void;

Asserts that actual includes expected.

Signature

declare function assertInclude(
  actual: string | undefined,
  expected: string,
  ..._: Array<never>
): void;

Asserts that value is an instance of constructor.

Signature

declare function assertInstanceOf<C extends (...args: any) => any>(
  value: unknown,
  constructor: C,
  message?: string,
  ..._: Array<never>
): asserts value is InstanceType<C>;

assertMatch

Added in v4.0.0 Source

Asserts that actual matches regExp.

Signature

declare function assertMatch(actual: string, regExp: RegExp, ..._: Array<never>): void;

assertNone

Added in v4.0.0 Source

Asserts that option is None.

Signature

declare function assertNone<A>(
  option: Option<A>,
  ..._: Array<never>
): asserts option is None<never>;

assertSome

Added in v4.0.0 Source

Asserts that option is Some and contains a value equal to expected.

Signature

declare function assertSome<A>(
  option: Option<A>,
  expected: A,
  ..._: Array<never>
): asserts option is Some<A>;

Asserts that result is Success and contains a value equal to expected.

Signature

declare function assertSuccess<A, E>(
  result: Result<A, E>,
  expected: A,
  ..._: Array<never>
): asserts result is Success<A, never>;

assertTrue

Added in v4.0.0 Source

Asserts that self is true.

Signature

declare function assertTrue(self: unknown, message?: string, ..._: Array<never>): asserts self;

Asserts that a is undefined.

Signature

declare function assertUndefined<A>(a: A | undefined, ..._: Array<never>): asserts a is undefined;

Asserts that actual is deeply strictly equal to expected using Node's assert.deepStrictEqual.

Signature

declare function deepStrictEqual<A>(
  actual: A,
  expected: A,
  message?: string,
  ..._: Array<never>
): void;

doesNotThrow

Added in v4.0.0 Source

Asserts that thunk does not throw an error.

Signature

declare function doesNotThrow(thunk: () => void, message?: string, ..._: Array<never>): void;

fail

Added in v4.0.0 Source

Fails the current test with the provided error message.

Signature

declare function fail(message: string): void;

Asserts that actual is not deeply strictly equal to expected using Node's assert.notDeepStrictEqual.

Signature

declare function notDeepStrictEqual<A>(
  actual: A,
  expected: A,
  message?: string,
  ..._: Array<never>
): void;

strictEqual

Added in v4.0.0 Source

Asserts that actual is strictly equal to expected using Node's assert.strictEqual.

Signature

declare function strictEqual<A>(actual: A, expected: A, message?: string, ..._: Array<never>): void;

throws

Added in v4.0.0 Source

Asserts that thunk throws, optionally checking the thrown value against an expected Error or validation function.

Signature

declare function throws(thunk: () => void, error?: Error | (u: unknown) => undefined, ..._: Array<never>): void

throwsAsync

Added in v4.0.0 Source

Asserts that thunk throws or returns a rejected promise, optionally checking the failure value against an expected Error or validation function.

Signature

declare function throwsAsync(thunk: () => Promise<void>, error?: Error | (u: unknown) => undefined, ..._: Array<never>): Promise<void>