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.

Jest suppresses errors in describe callback when only running specific tests

See original GitHub issue

🐛 Bug Report

If you run a specific test (such as using --testNamePattern - there could be other ways, but this is how I found the bug), jest will eat any errors thrown outside of that test, skipping the test and sometimes complaining about a describe callback not returning a value.

I did do a very minor dive into this a while ago, before I determined the cause (as when I first started jest I was getting these strange “a describe callback must not return a value”, despite never returning a value) - somewhere internally something returns null instead of undefined, which jest doesn’t know it’s doing and hence complains to the developer.

To Reproduce

  1. Write a test file that errors outside of an test/it block, that is inside at least one describe block
  2. Run the test specifically using a parameter like --testNamePatten

Expected behavior

Jest tells me that the error happened, in the same manner it does when I run the describe block.

Jest also shouldn’t complain about a describe callback shouldn’t have a return value (which it does even if I’m running the describe block - let me know if you’d like me to make a separate issue for this)

Link to repl or repo (highly encouraged)

Here is an example repo.

Do npm run showcase to see the bug in action.

Heres what it outputs on my side:

PS C:\Users\G-Rath\workspace\projects-personal\js-bugs>  jest "--testNamePattern=^test$" --runTestsByPath test/test.spec.js
  console.log node_modules/jest-jasmine2/build/jasmine/Env.js:520
      ● Test suite failed to run

        A "describe" callback must not return a value.
        Returning a value from "describe" will fail the test in a future version of Jest.

        > 1 | describe('test', () => {
            |                        ^
          2 |   throw new Error();
          3 | 
          4 |   it('showcases the bug', () => {

          at addSpecsToSuite (node_modules/jest-jasmine2/build/jasmine/Env.js:522:17)
          at Object.<anonymous> (test/test.spec.js:1:24)


Test Suites: 1 skipped, 0 of 1 total
Tests:       1 skipped, 1 total
Snapshots:   0 total
Time:        2.03s
Ran all test suites within paths "test/test.spec.js".

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  Binaries:
    Node: 10.15.3 - C:\nodejs\node.EXE
    Yarn: 1.13.0 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.9.0 - ~\AppData\Roaming\npm\npm.CMD

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jeysalcommented, Apr 15, 2019

Fair enough - is there anything else I should do to make this more actionable, such as opening an issue for jest-jasmine2?

jest-circus will supersede jest-jasmine2 as the default test framework implementation soon, so that will solve it for most people anyway. It might not be trivial to fix the suppression in jest-jasmine2 so possibly not worth it for something that’s obsolete soon. You can opt in to jest-circus now if you want to try it out BTW 😃

0reactions
github-actions[bot]commented, Apr 30, 2022

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

How to avoid Jest warnings: A "describe" callback must not ...
I'm converting some Mocha tests to Jest, and Mocha's before() was throwing the same error: A "describe" callback must not return a value....
Read more >
React Testing Library and the “not wrapped in act” Errors
I recently upgraded React and React testing library. Very happy about the upgrade. But I start to see test errors like this: In...
Read more >
API Reference | React Hooks Testing Library
A function to rerender the test component, causing any hooks to be recalculated. If newProps are passed, they will replace the callback function's...
Read more >
A Comprehensive Guide To Error Handling In Node.js
Errors happen in every application. Devs have to decide: do you write code to handle the error? Suppress it? Notify the user?
Read more >
Command-line usage - mocha - w3resource
This will enforce a rule that tests must be written in "async" style, this means that each test provides a done callback or...
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