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

add 'test verify' hook #287

Closed
wants to merge 1 commit into from

Conversation

timbertson
Copy link

for use by frameworks to always perform verification / teardown after a test has run (but before it is declared successful or failed).

@tj
Copy link
Contributor

tj commented Feb 25, 2012

What's the use-case

@timbertson
Copy link
Author

Mocking / stubbing frameworks often have things like "make sure this function gets called". Obviously, they can't determine whether this has not happened until the test is complete.

I originally put this sort of thing (a call to mockframework.verifyAll()) in an "after test" hook, but an exception thrown from there does not seem to fail the test properly. Also, that requires you to write mockframework.verifyAll() as an afterEach in at least every file, while ideally this would be something the framework hooks up for you (thus the runner hook).

@tj
Copy link
Contributor

tj commented Jun 17, 2012

This issue has been inactive for over 1 month so I'm closing it. If you think it's still an issue re-open. - tjbot

@tj tj closed this Jun 17, 2012
@timbertson
Copy link
Author

I still think it's an issue. Apparently I don't have permission to re-open this. Is that a bug, or am I really not allowed to reopen it?

@tj tj reopened this Jun 17, 2012
@tj
Copy link
Contributor

tj commented Jun 17, 2012

I like the idea of being able to fail the previous test within the afterEach hook, but if possible (should be) it would be nice to avoid the extra hook, even if it's just something lame like:

afterEach(function(){
  if (somethingFailed) this.test.fail(msg)
})

@timbertson
Copy link
Author

@tj
Copy link
Contributor

tj commented Jun 19, 2012

looks reasonable, I'll pull it down in a bit and have a look

@tj tj closed this in 8e5cc0a Jun 19, 2012
jjoos added a commit to jjoos/mocha that referenced this pull request Oct 23, 2015
In version 1.2.1, support was added to fail test in the after each hook:
> * Added `this.test.error(err)` support to after each hooks. Closes mochajs#287

While migrating from teaspoon-mocha to karma-mocha, we discovered that
in the current mocha version this isn't supported anymore (or we don't
understand how). In teaspoon this behaviour seems to be patched (running
it with the exact same mocha.js 2.2.4 file, teaspoon and karma have
different behaviour), although I couldn't quickly pinpoint the code that
does that.

This patch adds this behaviour back to the code base, but also seems to
break certain behaviour (3 tests are failing with this pull request).
But I don't understand what those test failures exactly mean. Also I
found it quite difficult to add test coverage of this behaviour. Since
there aren't any tests calling `runTests`.

Help in figuring out what we've done wrong or how we could fix this pull
request, would be appreciated. Not supporting this behaviour anymore due
to added complexity in the code, would also be fine, but adding some
documentation about dropping this functionality would be nice.
jjoos added a commit to jjoos/mocha that referenced this pull request Mar 17, 2016
In version 1.2.1, support was added to fail test in the after each hook:
> * Added `this.test.error(err)` support to after each hooks. Closes mochajs#287

While migrating from teaspoon-mocha to karma-mocha, we discovered that
in the current mocha version this isn't supported anymore (or we don't
understand how). In teaspoon this behaviour seems to be patched (running
it with the exact same mocha.js 2.2.4 file, teaspoon and karma have
different behaviour), although I couldn't quickly pinpoint the code that
does that.

This patch adds this behaviour back to the code base, but also seems to
break certain behaviour (3 tests are failing with this pull request).
But I don't understand what those test failures exactly mean. Also I
found it quite difficult to add test coverage of this behaviour. Since
there aren't any tests calling `runTests`.

Help in figuring out what we've done wrong or how we could fix this pull
request, would be appreciated. Not supporting this behaviour anymore due
to added complexity in the code, would also be fine, but adding some
documentation about dropping this functionality would be nice.
jjoos added a commit to jjoos/mocha that referenced this pull request Mar 17, 2016
In version 1.2.1, support was added to fail test in the after each hook:
> * Added `this.test.error(err)` support to after each hooks. Closes mochajs#287

While migrating from teaspoon-mocha to karma-mocha, we discovered that
in the current mocha version this isn't supported anymore (or we don't
understand how). In teaspoon this behaviour seems to be patched (running
it with the exact same mocha.js 2.2.4 file, teaspoon and karma have
different behaviour), although I couldn't quickly pinpoint the code that
does that.

This patch adds this behaviour back to the code base, but also seems to
break certain behaviour (3 tests are failing with this pull request).
But I don't understand what those test failures exactly mean. Also I
found it quite difficult to add test coverage of this behaviour. Since
there aren't any tests calling `runTests`.

Help in figuring out what we've done wrong or how we could fix this pull
request, would be appreciated. Not supporting this behaviour anymore due
to added complexity in the code, would also be fine, but adding some
documentation about dropping this functionality would be nice.
jjoos added a commit to jjoos/mocha that referenced this pull request Mar 17, 2016
In version 1.2.1, support was added to fail test in the after each hook:
> * Added `this.test.error(err)` support to after each hooks. Closes mochajs#287

While migrating from teaspoon-mocha to karma-mocha, we discovered that
in the current mocha version this isn't supported anymore (or we don't
understand how). In teaspoon this behaviour seems to be patched (running
it with the exact same mocha.js 2.2.4 file, teaspoon and karma have
different behaviour), although I couldn't quickly pinpoint the code that
does that.

This patch adds this behaviour back to the code base, but also seems to
break certain behaviour (3 tests are failing with this pull request).
But I don't understand what those test failures exactly mean. Also I
found it quite difficult to add test coverage of this behaviour. Since
there aren't any tests calling `runTests`.

Help in figuring out what we've done wrong or how we could fix this pull
request, would be appreciated. Not supporting this behaviour anymore due
to added complexity in the code, would also be fine, but adding some
documentation about dropping this functionality would be nice.
jjoos added a commit to jjoos/mocha that referenced this pull request Mar 17, 2016
In version 1.2.1, support was added to fail test in the after each hook:
>* Added `this.test.error(err)` support to after each hooks. Closes mochajs#287

While migrating from teaspoon-mocha to karma-mocha, we discovered that
in the current mocha version this isn't supported anymore. That
behaviour has been changed in: ebc6aee
without any documentation change.

If this was a conscious decision adding some documentation about
dropping this functionality would then be nice. The old behaviour is
documented in:
https://github.com/mochajs/mocha/wiki/Conditionally-failing-tests-in-afterEach()-hooks
.
jjoos added a commit to jjoos/mocha that referenced this pull request Mar 17, 2016
In version 1.2.1, support was added to fail test in the after each hook:
>* Added `this.test.error(err)` support to after each hooks. Closes mochajs#287

While migrating from teaspoon-mocha to karma-mocha, we discovered that
in the current mocha version this isn't supported anymore. That
behaviour has been changed in: ebc6aee
without any documentation change.

If this was a conscious decision adding some documentation about
dropping this functionality would then be nice. The old behaviour is
documented in:
https://github.com/mochajs/mocha/wiki/Conditionally-failing-tests-in-afterEach()-hooks
.
jjoos added a commit to jjoos/mocha that referenced this pull request Mar 17, 2016
In version 1.2.1, support was added to fail test in the after each hook:
>* Added `this.test.error(err)` support to after each hooks. Closes mochajs#287

While migrating from teaspoon-mocha to karma-mocha, we discovered that
in the current mocha version this isn't supported anymore. That
behaviour has been changed in: ebc6aee
without any documentation change.

If this was a conscious decision adding some documentation about
dropping this functionality would then be nice. The old behaviour is
documented in:
https://github.com/mochajs/mocha/wiki/Conditionally-failing-tests-in-afterEach()-hooks
.
jjoos added a commit to jjoos/mocha that referenced this pull request Mar 23, 2016
In version 1.2.1, support was added to fail test in the after each hook:
>* Added `this.test.error(err)` support to after each hooks. Closes mochajs#287

While migrating from teaspoon-mocha to karma-mocha, we discovered that
in the current mocha version this isn't supported anymore. That
behaviour has been changed in: ebc6aee
without any documentation change.

If this was a conscious decision adding some documentation about
dropping this functionality would then be nice. The old behaviour is
documented in:
https://github.com/mochajs/mocha/wiki/Conditionally-failing-tests-in-afterEach()-hooks
.
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

Successfully merging this pull request may close these issues.

2 participants