Mocha: unhelpful error when describe lacks second argument

Created on 13 Jun 2015  Â·  12Comments  Â·  Source: mochajs/mocha

➜  temp  cat test/test.js
it('rulz')
describe('very cofee')
it('sucks')

➜  temp  mocha
/usr/local/lib/node_modules/mocha/lib/interfaces/bdd.js:49
      fn.call(suite);
        ^
TypeError: Cannot read property 'call' of undefined
    at context.describe.context.context (/usr/local/lib/node_modules/mocha/lib/interfaces/bdd.js:49:9)
    at Object.<anonymous> (/Users/dasilvacontin/temp/test/test.js:2:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at /usr/local/lib/node_modules/mocha/lib/mocha.js:192:27
    at Array.forEach (native)
    at Mocha.loadFiles (/usr/local/lib/node_modules/mocha/lib/mocha.js:189:14)
    at Mocha.run (/usr/local/lib/node_modules/mocha/lib/mocha.js:422:31)
    at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:398:16)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3
confirmed-bug

Most helpful comment

Still an issue.
To replicate it:

  • Type describe('') into any of your spec files, as the beginning of a new suite you intend to write.
  • Instead of filling out your describe, go away from your machine and forget you typed the incomplete block.
  • Try to run your normal test command, find the above error trace, and proceed to waste an hour searching around for what it means.

All 12 comments

Throwing a TypeError or ignoring suites without a second argument (kinda like if they were pending) are ways to go.

I like the idea of having pending suites.

I also find the asymmetry surprising:

describe('something', function() {
  xit('skip it');
});

xdescribe('something', function() {}); // works fine
xdescribe('whatever'); // throws an error

+infinity

Still an issue.
To replicate it:

  • Type describe('') into any of your spec files, as the beginning of a new suite you intend to write.
  • Instead of filling out your describe, go away from your machine and forget you typed the incomplete block.
  • Try to run your normal test command, find the above error trace, and proceed to waste an hour searching around for what it means.

I just wasted a good amount of time trying to find out what was wrong with my tests. I had written a backbone describe so that I wouldn't forget to test a given functionality, but I didn't pass a callback to the describe function, because I wasn't intending to implement the test right now. I was going to implement other tests first, and then return and complete this describe with an actual callback which would have the actual tests in it functions. It would have been much easir for me to diagnose the problem if mocha had said me _"Invalid describe definition without callback argument."_ or something like that.

@UlyssesAlves I can't recreate this behavior. What version of mocha are you running?

@Munter I'm using Mocha version 2.5.3. Here is a snippet of a scenario which will reproduce the issue as described above:

describe("This is a test suite with a callback function parameter.", function() {
    it('Some test', function() {
        assert.equal(1, 1);
    });
});

describe("This test suite has no callback parameter and will produce an error which is hard to debug.");

In mocha 3 this is the output of the above test:

$ ./bin/mocha test/describe.js 


  This is a test suite with a callback function parameter.
    ✓ Some test


  1 passing (7ms)

Seems to be fixed

That's great! I'm going to update my project to the latest version of mocha then. I think @dasilvacontin (or some project member) should close the issue by now. Unless, of course, if this is still an issue for him or for someone else.

@Munter @UlyssesAlves After reading that snippet, I was expecting to see a pending suite in the output. What about you?

@dasilvacontin It does strike me as a bit odd that suites with no tests simply disappear completely in the output

@dasilvacontin sure. I think it would be better to see a pending suítes report so that we don't forget that our tests are not complete yet and that we have empty _describe_ directives which need to be filled with actual test cases.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jamietre picture jamietre  Â·  3Comments

adamhooper picture adamhooper  Â·  3Comments

robertherber picture robertherber  Â·  3Comments

eschwartz picture eschwartz  Â·  3Comments

jmiller-airfox picture jmiller-airfox  Â·  3Comments