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.

Regression: Jest 26 spec tests - runner process never stops after test exception

See original GitHub issue

Current Behavior

Previously - before the update that introduced Jest 26 - missing dependency were outlined within the spec tests very nicely/clearly.

But now: Post - Jest 26 update:

  1. After the test fails: The process never stop running - and you now have to force kill the tests.
  2. We now get these “unclear” errors. I.e. errors provided have become very opaque. Example:
[DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:28824) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'element' -> object with constructor 'Object'
    |     property 'componentProvider' -> object with constructor 'Object'
    --- property 'parent' closes the circle

Expected Behavior

In the versions prior to Jest 26 - the error was much, much clearer - and pointed to the exact issue at hand:

NullInjectorError: StaticInjectorError(DynamicTestModule)[HttpClient]:
      StaticInjectorError(Platform: core)[HttpClient]:
        NullInjectorError: No provider for HttpClient!

I feel this is regression as we now - have to “guess” what is missing from the tests - this leads to a much worse DX 😦

Steps to Reproduce

Create a simple service that has a simple dependency on something. Example: ensure your service has DI of: HttpClient in it.

Example:

export class NetflixService implements MovieProvider {
  constructor(private http: HttpClient) {

Inject this “new” service into your component.

Run your component spec test - without mocking out any of your dependency.

Failure Logs

(node:25892) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will termin
ate the Node.js process with a non-zero exit code.
(node:28824) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'element' -> object with constructor 'Object'
    |     property 'componentProvider' -> object with constructor 'Object'
    --- property 'parent' closes the circle
    at stringify (<anonymous>)
    at writeChannelMessage (internal/child_process/serialization.js:117:20)
    at process.target._send (internal/child_process.js:779:17)
    at process.target.send (internal/child_process.js:677:19)
    at reportSuccess (C:\nrwl_10\node_modules\jest-runner\node_modules\jest-worker\build\workers\processChild.js:67:11)
(node:28824) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a
 catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI fla
g `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:28824) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will termin
ate the Node.js process with a non-zero exit code.

However - this should actually show me something like:

NullInjectorError: StaticInjectorError(DynamicTestModule)[HttpClient]:
      StaticInjectorError(Platform: core)[HttpClient]:
        NullInjectorError: No provider for HttpClient!

Environment

"dependencies": {
    "@angular/animations": "^10.1.3",
    "@angular/common": "^10.1.3",
    "@angular/compiler": "^10.1.3",
    "@angular/core": "^10.1.3",
    "@angular/forms": "^10.1.3",
    "@angular/platform-browser": "^10.1.3",
    "@angular/platform-browser-dynamic": "^10.1.3",
    "@angular/router": "^10.1.3",
    "@nrwl/angular": "10.3.1",
    "core-js": "^2.5.4",
    "rxjs": "~6.5.5",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1001.3",
    "@angular-devkit/build-ng-packagr": "~0.1001.3",
    "@angular/cli": "~10.1.3",
    "@angular/compiler-cli": "^10.1.3",
    "@angular/language-service": "^10.1.3",
    "@nrwl/cli": "10.3.1",
    "@nrwl/cypress": "10.3.1",
    "@nrwl/jest": "10.3.1",
    "@nrwl/workspace": "10.3.1",
    "@types/jest": "26.0.8",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "cypress": "4.12.1",
    "dotenv": "6.2.0",
    "jest": "26.2.2",
    "jest-preset-angular": "8.3.1",
    "ng-packagr": "^10.1.0",
    "prettier": "2.1.2",
    "ts-jest": "26.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~6.1.0",
    "typescript": "~4.0.3"
  }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
Lonli-Loklicommented, Mar 29, 2021

Its not stale, bot.

4reactions
ranemloccommented, Nov 4, 2020

Agree with @ubergeoff

We are experiencing this same issue for a while in our project with 100+ libraries and it is really doing our lives a bit more miserable. Not just the real error is hidden, but also the tests will continue running forever, what leads to many builds hanging until the Jenkins job times out and gets killed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest hangs after running test despite done() - Stack Overflow
It gets stuck after the message "ran all tests" and I've to explicitly pass quit command. I'm calling done() but it never completes....
Read more >
Troubleshooting - Jest
When Jest executes the test that contains the debugger statement, execution will pause and you can examine the current scope and call stack....
Read more >
Testing Overview - React
Jest is a JavaScript test runner that lets you access the DOM via jsdom . While jsdom is only an approximation of how...
Read more >
test — Regression tests package for Python — Python 3.11.1 ...
Exception to be raised when a test fails. This is deprecated in favor of unittest -based tests and unittest.TestCase 's assertion methods.
Read more >
How To Deal With "Element is not clickable at point” Exception ...
Any automation testing using Selenium (or Cypress) involves interacting with the WebElements available in the DOM.
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