Skip to content

🚀 Feature: this.test.error() in "after all" hook should throw #4515

Open
@papb

Description

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

Steps to Reproduce

  • mkdir temp && cd temp && npm init -y && npm i -D mocha

  • Create test/test.js:

const assert = require('assert');

describe('First test block', function() {
	after(function() {
		// I know this code doesn't make sense in real life, it's just to show the issue
		this.test.error(new Error());
	});

	it('First test', function() {
		assert.strictEqual(true, true);
	});
});

describe('Second test block', function() {
	it('Second test', function() {
		assert.strictEqual(true, true);
	});
});
  • Run npx mocha test/*.js && echo 'ok'

Expected behavior: Mocha should exit with nonzero exit code and tell me that something is wrong.

Actual behavior:

  First test block
    √ First test
ok

Mocha completely swallowed the error and exited with exit code 0. Some tests didn't even run!

Reproduces how often: Every time

Versions

  • The output of npx mocha --version: 8.2.1
  • The output of node --version: v12.14.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: usabilityconcerning user experience or interfacestatus: accepting prsMocha can use your help with this one!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions