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

Mocha.run throws a TypeError if callback is not provided #1496

Closed
flowersinthesand opened this issue Jan 8, 2015 · 5 comments
Closed

Mocha.run throws a TypeError if callback is not provided #1496

flowersinthesand opened this issue Jan 8, 2015 · 5 comments
Labels
type: bug a defect, confirmed by a maintainer

Comments

@flowersinthesand
Copy link

To reproduce the issue, install Mocha 2.1.0 and run this script on Node console.

var Mocha = require("mocha");
var mocha = new Mocha();
mocha.addFile("./test.js");
mocha.run();

Here is test.js

it("nothing", function() {});

Then, I get:

Donghwan@DONGHWAN ~/Documents/GitHub/vibe-javascript-client (master)
$ node test-runner


  √ nothing

  1 passing (7ms)


c:\Users\Donghwan\Documents\GitHub\vibe-javascript-client\node_modules\mocha\lib\mocha.js:414
          fn(failures);
          ^
TypeError: undefined is not a function
    at done (c:\Users\Donghwan\Documents\GitHub\vibe-javascript-client\node_modules\mocha\lib\mocha.js:414:11)
    at Runner.<anonymous> (c:\Users\Donghwan\Documents\GitHub\vibe-javascript-client\node_modules\mocha\lib\runner.js:590:5)
    at Runner.emit (events.js:117:20)
    at c:\Users\Donghwan\Documents\GitHub\vibe-javascript-client\node_modules\mocha\lib\runner.js:597:10
    at c:\Users\Donghwan\Documents\GitHub\vibe-javascript-client\node_modules\mocha\lib\runner.js:518:7
    at next (c:\Users\Donghwan\Documents\GitHub\vibe-javascript-client\node_modules\mocha\lib\runner.js:248:23)
    at Object._onImmediate (c:\Users\Donghwan\Documents\GitHub\vibe-javascript-client\node_modules\mocha\lib\runner.js:276:5)
    at processImmediate [as _immediateCallback] (timers.js:345:15)

2.0.1 works fine. As the wiki page shows use of mocha.run(), I think it's a regression in 2.1.0. A workaround is to pass an empty callback.

It looks like that 30582e6 is the cause. Before executing fn(failures);, it should check if fn is available.

@julien-f
Copy link

Same issue here, the workaround solved it for now.

@flowersinthesand
Copy link
Author

@dasilvacontin As @julien-f experienced the same issue, you may want to change the label, unconfirmed, to something like invalid or bug?

@dasilvacontin
Copy link
Contributor

Sure, thanks for the heads up, @flowersinthesand!

@dasilvacontin dasilvacontin added type: bug a defect, confirmed by a maintainer status: accepting prs Mocha can use your help with this one! and removed Unconfirmed labels Jan 28, 2015
@dasilvacontin
Copy link
Contributor

PR #1520 fixes this issue.

travisjeffery pushed a commit that referenced this issue Feb 3, 2015
In .run(fn), check if fn exists before executing the callback, fixes #1496
@OKNoah
Copy link

OKNoah commented Feb 24, 2015

Will there be a release with this in it?

@boneskull boneskull removed the status: accepting prs Mocha can use your help with this one! label Oct 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

No branches or pull requests

5 participants