Repository: nodejs/node
File: lib/internal/test_runner/test.js (JavaScript)

Code before:
          this.fail(hook.error);
        }
      });
    }
    if (name === 'afterEach') {
      // afterEach hooks for the current test should run in the order that they
      // are created. However, the current test's afterEach hooks should run
      // prior to any ancestor afterEach hooks.
      ArrayPrototypeSplice(this.hooks[name], this.hooks.ownAfterEachCount, 0, hook);
      this.hooks.ownAfterEachCount++;
    } else {
      ArrayPrototypePush(this.hooks[name], hook);
    }
  }

  fail(err) {
    if (this.error !== null) {
      return;
    }

    if (this.expectFailure) {
      if (typeof this.expectFailure === 'object' &&
          this.expectFailure.match !== undefined) {
        const { match: validation } = this.expectFailure;
        try {
          const { throws } = assert;
          const errorToCheck = (err?.code === 'ERR_TEST_FAILURE' &&
            err?.failureType === kTestCodeFailure &&
            err.cause) ?
            err.cause : err;
          throws(() => { throw errorToCheck; }, validation);
        } catch (e) {
          this.passed = false;
          this.error = new ERR_TEST_FAILURE(
            'The test failed, but the error did not match the expected validation',
            kTestCodeFailure,
          );
          this.error.cause = e;
          return;
        }
      }
      this.passed = true;
    } else {
      this.passed = false;
    }

    this.error = err;
  }

  pass() {
    if (this.error == null && this.expectFailure && !this.skipped) {

Review comment (suggestion):
nit: i think it would be for searchability to use `assert.throws` instead of just `throws`.

Code after:
        if (hook.error != null) {
          this.fail(hook.error);
        }
      });
    }
    if (name === 'afterEach') {
      // afterEach hooks for the current test should run in the order that they
      // are created. However, the current test's afterEach hooks should run
      // prior to any ancestor afterEach hooks.
      ArrayPrototypeSplice(this.hooks[name], this.hooks.ownAfterEachCount, 0, hook);
      this.hooks.ownAfterEachCount++;
    } else {
      ArrayPrototypePush(this.hooks[name], hook);
    }
  }

  fail(err) {
    if (this.error !== null) {
      return;
    }

    if (this.expectFailure) {
      if (typeof this.expectFailure === 'object' &&
          this.expectFailure.match !== undefined) {
        const { match: validation } = this.expectFailure;
        try {
          const errorToCheck = (
            err?.code === 'ERR_TEST_FAILURE' &&
            err?.failureType === kTestCodeFailure &&
            err.cause
          ) ?
            err.cause :
            err;
          // eslint-disable-next-line no-restricted-syntax
          assert.throws(() => { throw errorToCheck; }, validation);
        } catch (e) {
          this.passed = false;
          this.error = new ERR_TEST_FAILURE(
            'The test failed, but the error did not match the expected validation',
            kTestCodeFailure,
          );
          this.error.cause = e;
          return;
        }
      }
      this.passed = true;
    } else {
      this.passed = false;
    }

    this.error = err;