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

unhelpful error when describe lacks second argument #1744

Closed
dasilvacontin opened this issue Jun 13, 2015 · 12 comments
Closed

unhelpful error when describe lacks second argument #1744

dasilvacontin opened this issue Jun 13, 2015 · 12 comments
Labels
type: bug a defect, confirmed by a maintainer

Comments

@dasilvacontin
Copy link
Contributor

  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
@dasilvacontin dasilvacontin added type: bug a defect, confirmed by a maintainer status: accepting prs Mocha can use your help with this one! labels Jun 13, 2015
@dasilvacontin
Copy link
Contributor Author

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.

@ndhoule
Copy link
Contributor

ndhoule commented Jun 20, 2015

I also find the asymmetry surprising:

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

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

@hellboy81
Copy link

+infinity

@JoeCostanzo
Copy link

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.

@UlyssesAlves
Copy link

UlyssesAlves commented Aug 11, 2016

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.

@Munter
Copy link
Member

Munter commented Aug 13, 2016

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

@UlyssesAlves
Copy link

@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.");

@Munter
Copy link
Member

Munter commented Aug 15, 2016

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

@UlyssesAlves
Copy link

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.

@dasilvacontin
Copy link
Contributor Author

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

@Munter
Copy link
Member

Munter commented Aug 18, 2016

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

@UlyssesAlves
Copy link

@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.

boneskull pushed a commit that referenced this issue Sep 19, 2016
1999 pushed a commit to 1999/mocha that referenced this issue Sep 19, 2016
…roperty-currentretry

* upstream/master:
  helpful error when necessary suite callback omitted; closes mochajs#1744
  Fix an issue and add relevant tests when describe and xdescribe fail when not supplied with a callback (issue mochajs#1744).
  rename more fixtures; closes mochajs#2383
  Report non-match to STDERR and exit if no files are matched (mochajs#2450)
  Exit process with correct error codes (mochajs#2445)
  fix test files not using .spec suffix fix test fixtures not using .fixture suffix
  always halt execution when async skip() called; closes mochajs#2465 (mochajs#2479)
  avoid test flake in "delay" test; closes mochajs#2469 (mochajs#2470)
  revert accidental change to bin paths
  disregard function names when testing under Node.js 6.5.0; closes mochajs#2467 (mochajs#2477)
  lints more files; add more files to lint check; closes mochajs#2457
  adds *.orig to .gitignore
  Exclude the --inspect flag
  fix check-leaks to catch a leak whose name begins with 'd'
1999 pushed a commit to 1999/mocha that referenced this issue Sep 22, 2016
…-files-cache

* upstream/master:
  attempt windows-friendly reproducible case for mochajs#2315
  fix: fix uncaught TypeError if error occurs on next tick, closes mochajs#2315 (mochajs#2439)
  helpful error when necessary suite callback omitted; closes mochajs#1744
  Fix an issue and add relevant tests when describe and xdescribe fail when not supplied with a callback (issue mochajs#1744).
  rename more fixtures; closes mochajs#2383
  Report non-match to STDERR and exit if no files are matched (mochajs#2450)
  Exit process with correct error codes (mochajs#2445)
  fix test files not using .spec suffix fix test fixtures not using .fixture suffix
  always halt execution when async skip() called; closes mochajs#2465 (mochajs#2479)
  avoid test flake in "delay" test; closes mochajs#2469 (mochajs#2470)
  revert accidental change to bin paths
  disregard function names when testing under Node.js 6.5.0; closes mochajs#2467 (mochajs#2477)
  lints more files; add more files to lint check; closes mochajs#2457
  adds *.orig to .gitignore
  Exclude the --inspect flag
  fix check-leaks to catch a leak whose name begins with 'd'
@boneskull boneskull removed the status: accepting prs Mocha can use your help with this one! label Oct 10, 2016
sgilroy pushed a commit to TwineHealth/mocha that referenced this issue Feb 27, 2019
sgilroy pushed a commit to TwineHealth/mocha that referenced this issue Feb 27, 2019


- works for QUnit as well
- renamed some files
- fixed unclear "only" tests
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

7 participants