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
Using the HttpClientTestingModule and HttpTestingController provided by Angular makes mocking out results and testing http requests simple by providing many useful methods for checking http requests and providing mock responses for each request.
waitForAsynclinkWraps a test function in an asynchronous test zone. The test will automatically complete when all asynchronous calls within this zone are done. Can be used to wrap an inject call.
In my own case, the snippet below resolved my issue.
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
For me, swapping this:
beforeEach(async(() => { //...
for this:
beforeEach(() => { //...
in a test that ran before the one which was apparently failing, helped me to identify the real culprit.
Details: I was getting this error for tests that failed in the entire suite, but passed when run individually. It turned out that it was an earlier test, which was being run asynchronously, that was actually failing.
(That test had a template that had an error in the code, solved with the help of this Stack Overflow answer.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With