@nevware21/tripwire - v0.1.7
    Preparing search index...

    Class AssertionFailure<T>

    This error is thrown when the requested assertion check fails.

    • Extends standard Error class

    The message for the error.

    The additional properties for the error.

    The function to use as the starting point for the stack trace.

    The new AssertionFailure instance.

    interface CustomProps {
    expected: number;
    actual: number;
    }

    try {
    throw new AssertionFailure<CustomProps>("Expected value does not match actual value", { expected: 1, actual: 2 });
    } catch (e) {
    console.error(e.fullStack);
    console.log(e.toJSON());
    }

    console.error(error.message); // "Expected value does not match actual value"
    console.log(error.props?.expected); // 1
    console.log(error.props?.actual); // 2

    Type Parameters

    • T

      The type of the additional properties.

    • Static Hideconstructor

      Creates a new AssertionFailure with the given message and properties.

      Type Parameters

      • T

        The type of the additional properties.

      Parameters

      • Optionalmessage: string

        The message for the error.

      • Optionalprops: T

        The additional properties for the error.

      • OptionalstackStart: Function | Function[]

        The function to use as the starting point for the stack trace.

      Returns AssertionFailure<T>

      The new AssertionFailure.

      try {
      throw new AssertionFailure("Assertion failed", { expected: 1, actual: 2 });
      } catch (e) {
      console.error(e.fullStack);
      console.log(e.toJSON());
      }
    • Static Hideconstructor

      Creates a new AssertionFailure with the given message and properties.

      Type Parameters

      • T

        The type of the additional properties.

      Parameters

      • Optionalmessage: string

        The message for the error.

      • OptionalinnerEx: Error

        The error that caused this error to be thrown.

      • Optionalprops: T

        The additional properties for the error.

      • OptionalstackStart: Function | Function[]

        The function to use as the starting point for the stack trace.

      Returns AssertionFailure<T>

      The new AssertionFailure.

      try {
      throw new AssertionFailure("Assertion failed", new Error(), { expected: 1, actual: 2 });
      } catch (e) {
      console.error(e.fullStack);
      console.log(e.toJSON());
      }
    • Static

      Creates a new AssertionError with the given message and properties.

      Type Parameters

      • T

        The type of the additional properties.

      Parameters

      • Optionalmessage: string

        The message for the error.

      • Optionalprops: T

        The additional properties for the error.

      • OptionalstackStart: Function | Function[]

        An array of possible functions to use as the starting point for the stack trace.

      Returns AssertionError<T>

      The new AssertionError.

    • Static

      Creates a new AssertionError with the given message and properties.

      Type Parameters

      • T

        The type of the additional properties.

      Parameters

      • Optionalmessage: string

        The message for the error.

      • OptionalinnerEx: Error

        The error that caused this error to be thrown.

      • Optionalprops: T

        The additional properties for the error.

      • OptionalstackStart: Function | Function[]

        An array of possible functions to use as the starting point for the stack trace.

      Returns AssertionError<T>

      The new AssertionError.

    • Static

      Parameters

      • Optionalmessage: string

      Returns AssertionError

    • Static

      Parameters

      • Optionalmessage: string

      Returns Error

    Index

    Properties

    actual?: any

    The actual value that was seen. Changed to Mutable (from readonly) for backward compatibility in 0.1.6, but should be treated as read-only

    0.1.5

    expected?: any

    The value that was expected Changed to Mutable (from readonly) for backward compatibility in 0.1.6, but should be treated as read-only

    0.1.5

    fullStack: () => string

    Gets the full stack trace of the error, this will show all of the internal calls that lead to the error being thrown. Useful for debugging as generally the stack trace will only show the location where the error was thrown.

    Type Declaration

      • (): string
      • Returns string

        The full stack trace as a string.

    innerException: () => Error

    The error that caused this error to be thrown.

    message: string
    name: string
    operator?: string

    The operator used in the assertion Changed to Mutable (from readonly) for backward compatibility in 0.1.6, but should be treated as read-only

    0.1.5

    The original values of the properties before any modifications were made for backward compatibility with older versions of frameworks (like mocha). This allows for referencing the original values if needed, while still allowing the properties to be modified for compatibility reasons. This property and its properties are readonly to prevent modification and will only be set if any of the original properties (actual, expected, operator, showDiff) are present on the error object AND the values are modified to be different than the original values. If the original values are the same as the modified values, then this property will not be set. While the actual and expected properties are commonly also in the props object, these top-level properties are mutable and therefore it is possible that some frameworks may modify these properties directly on the error object.

    0.1.6

    props?: T

    Additional properties that are included in the error.

    showDiff?: boolean

    Indicates whether to show the difference between expected and actual values in the error message. Changed to Mutable (from readonly) for backward compatibility in 0.1.6, but should be treated as read-only

    0.1.5

    stack?: string
    stackTraceLimit: number

    The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

    The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

    If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

    Methods

    • Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

      const myObject = {};
      Error.captureStackTrace(myObject);
      myObject.stack; // Similar to `new Error().stack`

      The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

      The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

      The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

      function a() {
      b();
      }

      function b() {
      c();
      }

      function c() {
      // Create an error without stack trace to avoid calculating the stack trace twice.
      const { stackTraceLimit } = Error;
      Error.stackTraceLimit = 0;
      const error = new Error();
      Error.stackTraceLimit = stackTraceLimit;

      // Capture the stack trace above function b
      Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
      throw error;
      }

      a();

      Parameters

      • targetObject: object
      • OptionalconstructorOpt: Function

      Returns void

    • Converts the error to a JSON object.

      Parameters

      • Optionalstack: boolean

        Whether to include the stack trace in the JSON object.

      Returns any

      A JSON representation of the error.