async function assertThrowsAsync(
  fn,
  ErrorClass,
  msgIncludes = "",
  msg,
) {
  let doesThrow = false;
  let error = null;
  try {
    await fn();
  } catch (e) {
    if (e instanceof Error === false) {
      throw new AssertionError("A non-Error object was thrown or rejected.");
    }
    if (ErrorClass && !(e instanceof ErrorClass)) {
      msg =
        `Expected error to be instance of "${ErrorClass.name}", but got "${e.name}"${
          msg ? `: ${msg}` : "."
        }`;
      throw new AssertionError(msg);
    }
    if (
      msgIncludes && !stripColor(e.message).includes(stripColor(msgIncludes))
    ) {
      msg =
        `Expected error message to include "${msgIncludes}", but got "${e.message}"${
          msg ? `: ${msg}` : "."
        }`;
      throw new AssertionError(msg);
    }
    doesThrow = true;
    error = e;
  }
  if (!doesThrow) {
    msg = `Expected function to throw${msg ? `: ${msg}` : "."}`;
    throw new AssertionError(msg);
  }
  return error;
}
/**
 * Executes a function which returns a promise, expecting it to throw or reject.
 * If it does not, then it throws.  An error class and a string that should be
 * included in the error message can also be asserted.
 */
Executes a function which returns a promise, expecting it to throw or reject.
If it does not, then it throws.  An error class and a string that should be
included in the error message can also be asserted.
Executes a function which returns a promise expecting it to throw or reject . If it does not then it throws . An error class and a string that should be included in the error message can also be asserted .
async function assertThrowsAsync(
  fn,
  ErrorClass,
  msgIncludes = "",
  msg,
) {
  let doesThrow = false;
  let error = null;
  try {
    await fn();
  } catch (e) {
    if (e instanceof Error === false) {
      throw new AssertionError("A non-Error object was thrown or rejected.");
    }
    if (ErrorClass && !(e instanceof ErrorClass)) {
      msg =
        `Expected error to be instance of "${ErrorClass.name}", but got "${e.name}"${
          msg ? `: ${msg}` : "."
        }`;
      throw new AssertionError(msg);
    }
    if (
      msgIncludes && !stripColor(e.message).includes(stripColor(msgIncludes))
    ) {
      msg =
        `Expected error message to include "${msgIncludes}", but got "${e.message}"${
          msg ? `: ${msg}` : "."
        }`;
      throw new AssertionError(msg);
    }
    doesThrow = true;
    error = e;
  }
  if (!doesThrow) {
    msg = `Expected function to throw${msg ? `: ${msg}` : "."}`;
    throw new AssertionError(msg);
  }
  return error;
}
async function assertThrowsAsync ( fn , ErrorClass , msgIncludes = "" , msg , ) { let doesThrow = false ; let error = null ; try { await fn ( ) ; } catch ( e ) { if ( e instanceof Error === false ) { throw new AssertionError ( "A non-Error object was thrown or rejected." ) ; } if ( ErrorClass && ! ( e instanceof ErrorClass ) ) { msg = ` ${ ErrorClass . name } ${ e . name } ${ msg ? ` ${ msg } ` : "." } ` ; throw new AssertionError ( msg ) ; } if ( msgIncludes && ! stripColor ( e . message ) . includes ( stripColor ( msgIncludes ) ) ) { msg = ` ${ msgIncludes } ${ e . message } ${ msg ? ` ${ msg } ` : "." } ` ; throw new AssertionError ( msg ) ; } doesThrow = true ; error = e ; } if ( ! doesThrow ) { msg = ` ${ msg ? ` ${ msg } ` : "." } ` ; throw new AssertionError ( msg ) ; } return error ; }
Executes a function which returns a promise, expecting it to throw or reject.
Executes a function which returns a promise expecting it to throw or reject .