New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case skip()ed, beforeEach() hook still executed, afterEach() missed #2546

s100 opened this Issue Oct 17, 2016 · 4 comments


None yet
5 participants
Copy link

s100 commented Oct 17, 2016

This with Mocha 3.1.2. Source test file:

"use strict";
describe('outer', function() {

  beforeEach(function() {

  describe('inner', function() {
    beforeEach(function() {

    it('test case', function() {

    afterEach(function() {

  afterEach(function() {

Expected output: either "B" and "Y" should be printed, or neither "B" nor "Y" should be printed.

Actual output: "B" is printed, but not "Y":

      - test case

  0 passing (11ms)
  1 pending

In general,

  • If I call skip(), then I would not expect that inner beforeEach blocks would be executed.
  • If a beforeEach block is executed, then the corresponding afterEach blocks should also be executed, for symmetry.

This comment has been minimized.

Copy link

ORESoftware commented Oct 26, 2016

I do agree that it's strange and probably a bug that Y and Z do not run, but B does. That's just wrong.

However, I think the inner beforeEach will always run unless you call

    it.skip('test case', function() {

the this.skip() functionality is fundamentally different than it.skip etc, if you want to know why, I can explain more. It's merely bad naming on the part of Mocha authors, I think.

I don't it's well specified or understand what will happen if you call this.skip() inside a hook. Ideally it would be named, this.continue() or something like that, because all it means is that "we are done here" let's move to the next item.


This comment has been minimized.

Copy link

nullin commented May 2, 2017

Looks like a dup of #2286. I'll be great to get #2623 merged as that might solve this too.


This comment has been minimized.

Copy link

stale bot commented Oct 17, 2017

I am a bot that watches issues for inactivity.
This issue hasn't had any recent activity, and I'm labeling it stale. In 14 days, if there are no further comments or activity, I will close this issue.
Thanks for contributing to Mocha!

@stale stale bot added the stale label Oct 17, 2017


This comment has been minimized.

Copy link

philipwalton commented Oct 17, 2017

This is an issue for several projects I work on, so I'd like to see it stay open.

@stale stale bot removed the stale label Oct 17, 2017

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