Axinom Mosaic Libraries
    Preparing search index...
    • Test function. Checks that a synchronous function throws an error on execution. It returns a serialized thrown error. Allows easier inspection of the thrown error.

      The returned object is serialized because test runners can detect Error classes and decide to compare only message property, ignoring all others. Recommended to not compare returned type against an object of Error type.

      Type Parameters

      • TErrorType = any

      Parameters

      • fn: () => unknown

      Returns TErrorType

       const error = expectFailure<MosaicError>(() => syncFunction(param));

      expect(error.message).toBe('Some error message');
      expect(error.code).toBe('SOME_CODE');

      For async functions use rejectionOf