question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty describe block throws error

See original GitHub issue

🐛 Bug Report

If a describe block is left empty, with no tests passed to it, an error is thrown because the list of tests is not defined. Whether this is valid or not, it should probably return a specific message instead of a cryptic runtime error.

If I have an empty describe like:

describe('Scenario needing some tests')

It will fail with Cannot read property 'length' of undefined:

  ● Test suite failed to run

    TypeError: Cannot read property 'length' of undefined

      at Env.describe (node_modules/jest-jasmine2/build/jasmine/Env.js:297:27)
      at Object.<anonymous> (client/test/components/AccountChooser/AccountChooser-test.js:10:1)
          at Generator.next (<anonymous>)
          at new Promise (<anonymous>)
          at Generator.next (<anonymous>)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

Personally I find the workflow of creating a describe block for every set of tests I know I will need up front, and then coming back and filling them in as I get time, to be really useful. Some may argue that it should be considered invalid, but in that case it should throw an error explaining as much.

To Reproduce

Just create a describe instance with only a name param supplied

Expected behavior

Either no error at all, or a friendly error message like ‘Every describe block requires some tests’

Link to repl or repo (highly encouraged)

https://repl.it/repls/UnselfishAmusedNanocad

Run npx envinfo --preset jest

Paste the results here:


Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, May 22, 2018

This is basically #5558, but for describe instead of it/test. Wanna send a PR for it?

0reactions
github-actions[bot]commented, May 12, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why are empty catch blocks a bad idea? - Stack Overflow
Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution.
Read more >
throw - JavaScript - MDN Web Docs - Mozilla
The throw statement throws a user-defined exception. ... If no catch block exists among caller functions, the program will terminate.
Read more >
JavaScript Errors Try Catch Throw - W3Schools
The try statement allows you to define a block of code to be tested for errors while it is being executed. The catch...
Read more >
Error handling, "try...catch" - The Modern JavaScript Tutorial
The error throwing on line (*) from inside catch block “falls out” of try...catch and can be either caught by an outer try...catch...
Read more >
Poor Error Handling: Empty Catch Block - Fortify Taxonomy
The program records no evidence indicating the special situation, potentially frustrating any later attempt to explain the program's behavior. Recommendations.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found