Skip to content
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

this.skip() is also skipping teardown()/afterEach() #2148

Closed
laughinghan opened this issue Mar 8, 2016 · 10 comments
Closed

this.skip() is also skipping teardown()/afterEach() #2148

laughinghan opened this issue Mar 8, 2016 · 10 comments

Comments

@laughinghan
Copy link

    setup(function() {
      mock.innerHTML = 'Temporary stuff';
    });
    teardown(function() {
      mock.innerHTML = ''; // THIS ISN'T BEING RUN
    });
    test('test', function() {
      if ('some precondition is unmet') {
        this.skip();
      }
    });

With Mocha v2.4.5: http://jsbin.com/bijuru/edit?html,output
With latest master branch: http://jsbin.com/dajugel/edit?html,output

Observed: Temporary stuff is leftover from test setup

Expected: Temporary stuff should've been cleared by test teardown

@danielstjules
Copy link
Contributor

Confirmed as an issue. Likely extends to the bdd and other UIs as well.

suite('suite', function() {
  suiteSetup(function() {
    console.log('SUITE SETUP');
  });

  setup(function() {
    console.log('SETUP');
  });

  test('spec2', function() {
    console.log('SKIPPED SPEC');
    this.skip();
  });

  teardown(function() {
    console.log('TEADOWN');
  });

  suiteTeardown(function() {
    console.log('SUITE TEARDOWN');
  });
});

// =>

SUITE SETUP
SETUP
SKIPPED SPEC
SUITE TEARDOWN

@danielstjules
Copy link
Contributor

Note that the behavior is correct when using test.skip to skip the function. In that instance, the setup/beforeEach is never ran, so the teardown/afterEach is unnecessary.

It's only when dynamically skipping the spec that this occurs. In that case, the test is pending, however the setup/beforeEach has already ran.

@danielstjules danielstjules added the type: bug a defect, confirmed by a maintainer label Mar 21, 2016
@boneskull boneskull added confirmed status: waiting for author waiting on response from OP - more information needed and removed confirmed labels Jun 11, 2016
@boneskull
Copy link
Member

@megagon @danielstjules 8a37e01 was merged. Is this still an issue?

@laughinghan
Copy link
Author

@boneskull: yes it is, I'm able to repro using the testcase from the original issue report that uses latest master, you can see "Temporary stuff" isn't cleaned up: http://jsbin.com/dajugel/edit?html,output

@ScottFreeCode
Copy link
Contributor

I copied this down locally and tried it with a rebuilt browser mocha.js file and confirmed the issue is still present. In the process I also noticed how this is different from #2286/#2287: that was afterAll being skipped if beforeEach calls skip, this is afterEach being skipped if the test or the beforeEach calls skip.

@laughinghan
Copy link
Author

@ScottFreeCode: oh, thanks! Did you ever try #2168?

@ScottFreeCode
Copy link
Contributor

If I take the change from #2168 and rebuild mocha.js, it does seem to fix this issue. It could use some updates to the tests though.

@boneskull boneskull added duplicate and removed type: bug a defect, confirmed by a maintainer status: waiting for author waiting on response from OP - more information needed unconfirmed labels Nov 3, 2016
@boneskull
Copy link
Member

dupe of #2286 for all intents and purposes

@boneskull
Copy link
Member

See PR #2571

@laughinghan
Copy link
Author

Hey now, mine came first so strictly speaking #2286 is a dupe of this one 😜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants