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

All but last test both passes and fails when done is called twice #2057

Closed
dead-claudia opened this issue Jan 18, 2016 · 4 comments
Closed
Labels
area: reporters involving a specific reporter type: question support question

Comments

@dead-claudia
Copy link

Is this by design? It's not helpful with the HTML reporter.

Here's a repro for the BDD interface, but it's the case with all the ones that work in the browser:

<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.3.4/mocha.min.css">
<div id="mocha"></div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.3.4/mocha.min.js"></script>

<script>
mocha.setup("bdd")
describe("foo", function () {
    it("fails", function (done) {
        done()
        done(new Error("fail!"))
    })

    it("fails 2", function (done) {
        done()
        done(new Error("fail!"))
    })
})
mocha.run()
</script>
@drazisil drazisil added type: question support question area: reporters involving a specific reporter labels Mar 30, 2017
@fesebuv
Copy link

fesebuv commented Aug 24, 2017

Hello @isiahmeadows,
I believe that what you are describing is a bug related to the following issue: #2600

@ScottFreeCode
Copy link
Contributor

ScottFreeCode commented Aug 25, 2017

#2600 is unrelated; it's about determining successful done call based on number of arguments vs based on the argument being undefined.

This issue is pretty much expected behavior: Calling done more than once is a test error (regardless of whether another error is supplied to the second call), but calling done once is the normal way to pass a test, so the error when done is called more than once can only ever occur after the test is already believed to be passed due to the first done call.

[EDITTED TO ADD:] (As for the last test, Mocha presumes the test run is finished after its first done call, that's why it doesn't wait around for the second -- erroneous -- call to done in the last test.)

@jsocol
Copy link

jsocol commented Aug 25, 2017

The error from the test is getting passed to multiple on runnable.js#285, which leads to getting the Error('fail!') recorded instead of the usual done called multiple times error. Not sure if that's necessary/intentional. On line 275 there's a fallback || new Error(...) that can never happen because of the fallback on 285.

@ScottFreeCode
Copy link
Contributor

...getting the Error('fail!') recorded instead of the usual done called multiple times error. Not sure if that's necessary/intentional.

I'd guess it's intentional since the code would've actually been simpler if it weren't doing that, but it definitely would be clearer about done being called multiple times erroneously if it always used the "done called multiple times" error. I'm not sure what the rationale was for using the error passed to done instead, though -- or whether it could somehow print both...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: reporters involving a specific reporter type: question support question
Projects
None yet
Development

No branches or pull requests

5 participants