angularkarma-jasmine

How to figure out which Angular unit test caused an error


My suite of unit tests runs flawlessly in a Bash shell, but when I try to commit from within VS Code, I get this:

...
[1A[2KChrome Headless 132.0.0.0 (Windows 10): Executed 1200 of 1527 (skipped 6)[32m SUCCESS[39m (0 secs / 9.129 secs)
[1A[2K[31mChrome Headless 132.0.0.0 (Windows 10) ERROR[39m
  An error was thrown in afterAll
  [object Event] thrown
Chrome Headless 132.0.0.0 (Windows 10): Executed 1200 of 1527 (skipped 6)[31m ERROR[39m (0 secs / 9.129 secs)
Chrome Headless 132.0.0.0 (Windows 10) ERROR
  An error was thrown in afterAll
  [object Event] thrown
[1A[2KChrome Headless 132.0.0.0 (Windows 10): Executed 1200 of 1527 (skipped 6)[31m ERROR[39m (12.497 secs / 9.129 secs)

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================
[1A[2KChrome Headless 132.0.0.0 (Windows 10): Executed 1201 of 1527 (skipped 6)[31m ERROR[39m (12.497 secs / 9.142 secs)
31 01 2025 06:30:21.978:ERROR [karma-server]: UncaughtException: TypeError: Cannot read property 'ele' of null
    at HTMLReporter.specSuccess.specSkipped.specFailure (C:\Users\user\source\repos\Dev-16-3\node_modules\karma-htmlfile-reporter\index.js:233:42)
    at HTMLReporter.BaseReporter.onSpecComplete (C:\Users\user\source\repos\Dev-16-3\node_modules\karma\lib\reporters\base.js:107:12)
    at Server.<anonymous> (C:\Users\user\source\repos\Dev-16-3\node_modules\karma\lib\events.js:40:26)
    at Server.emit (events.js:412:35)
    at Browser.onResult (C:\Users\user\source\repos\Dev-16-3\node_modules\karma\lib\browser.js:164:20)
    at Socket.<anonymous> (C:\Users\user\source\repos\Dev-16-3\node_modules\karma\lib\browser.js:218:42)
    at Socket.emit (events.js:400:28)
    at Socket.emitUntyped (C:\Users\user\source\repos\Dev-16-3\node_modules\socket.io\dist\typed-events.js:69:22)
    at C:\Users\user\source\repos\Dev-16-3\node_modules\socket.io\dist\socket.js:466:39
    at processTicksAndRejections (internal/process/task_queues.js:77:11)

I get that a test is failing in afterAll. The failure is TypeError: Cannot read property 'ele' of null - fair enough, but exactly which test was causing the problem?

As you can (probably) see, there are no references to our application code in this stack trace or anywhere else in this error report, so is there a way to find out which test failed other than by enabling just one test at a time, which would be very tedious with 1,500+ tests and also might not show the problem as it appears to be transient.

This is Angular 14.


Solution

  • You are running the tests in headless Chrome. Run the tests in a regular Chrome (non-headless) instead. When starting the tests, a new browser window will open with the Karma UI, where you can see after which test the problem occurs.

    ng test --browsers=Chrome