Type Alias ErrorMatchOptions

ErrorMatchOptions: PartialWithNullable<{
    matchConstructor: ErrorConstructor | (new (...args: any[]) => Error);
    matchMessage: string | RegExp;
}>

A type that represents possible error matching patterns. This is used by the .throws and isError, guards in @augment-vir/assert as well as itCases in @augment-vir/test. Each property is optional, and whichever properties are provided will be checked.

Type declaration

  • matchConstructor: ErrorConstructor | (new (...args: any[]) => Error)

    A constructor that the error will be compared to with instanceof: error instanceof options.matchConstructor. If this property is omitted, the error's constructor or inheritance will not be checked.

  • matchMessage: string | RegExp

    A string or RegExp that an error's message will be compared with.

    • If this is a string, the error's message will checked for containing the given string (not strictly equalling it): error.message.includes(options.matchMessage)
    • If this is a RegExp, the error's message will be tested against it: error.message.match(options.matchMessage)

    If this property is omitted, the error message won't be checked at all.

import {assert, type ErrorMatchOptions} from '@augment-vir/assert';

// define the options
const matchOptions: ErrorMatchOptions = {
matchConstructor: Error,
matchMessage: 'some error',
};

assert.throws(
() => {
throw new Error('some error');
},
// use the options
matchOptions,
); // this assertion will pass