"An error was thrown in afterAll\n[object ErrorEvent] thrown" - Angular 4 Unit tests

Tetali pratyush picture Tetali pratyush · May 21, 2018 · Viewed 8.6k times · Source

While I was working on Angular 4 unit tests, one of the pages which uses google maps and agm package showed an error:

An error was thrown in afterAll\n[object ErrorEvent] thrown

Does anyone know what the issue could be?

Console Screenshot

Answer

Paul Acheson picture Paul Acheson · Jul 3, 2018

I was also looking for a solution to this issue and found that if I run my test as usual via terminal (ng test), then click debug in the Karma runner Chrome window, then open my dev console, I could see the real output of the error.

I saw a suggestion to run the unit tests with an additional flag; this didn't work for me, it may be worth a try however:

  • CLI v6.x --sourceMap=false
  • CLI v1.x --sourcemaps=false

Source: https://stackoverflow.com/a/46840229

In my case I was mocking a third party package class, and I'd forgotten to mock one of the function calls in the mocked class in my unit tests; it was throwing an error which wasn't bubbling to the terminal.

Apologies that this doesn't solve the error in itself, but perhaps it will get you closer to debugging the crux of the issue and finding a solution as it did for me.