all files / core/errors/ error-match-error.ts

93.75% Statements 15/16
55% Branches 11/20
100% Functions 2/2
92.86% Lines 13/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28       52×   52×         50× 40×   10× 10×            
import { MatchError } from "./match-error";
 
export class ErrorMatchError extends MatchError {
 
  //public constructor(actualError: Error, shouldMatch: boolean);
  public constructor(actualError: Error, shouldMatch: boolean, expectedErrorType?: new (...args: Array<any>) => Error, expectedErrorMessage?: string) {
    super(actualError, expectedErrorMessage, "");
 
    if (!actualError === shouldMatch) {
      if (shouldMatch) {
        this._message = `Expected an error to be thrown but no errors were thown.`;
      }
      else {
        this._message = `Expected an error not to be thrown but an error was thown.`;
      }
    }
    else if (actualError instanceof expectedErrorType !== shouldMatch) {
      this._message = `Expected an error of type ${expectedErrorType["name"]} to ${!shouldMatch ? "not ": ""}have been thrown, but it was${!shouldMatch ? "": "n't"}.`;
    }
    else Eif (actualError.message === expectedErrorMessage !== shouldMatch) {
      this._message = `Expected an error with message "${expectedErrorMessage}" to ${!shouldMatch ? "not ": ""}have been thrown, but it was${!shouldMatch ? "": "n't"}.`;
    }
    else {
      this._message = `Expected an error with message "${expectedErrorMessage}" and type ${expectedErrorType["name"]} to ${!shouldMatch ? "not ": ""}have been thrown, but it was${!shouldMatch ? "": "n't"}.`;
    }
  }
}