Reputation: 2455
I just started writing unit tests for an existing Angular app using Jasmine, and around 50% of the time, I get the following error:
Chrome 72.0.3626 (Mac OS X 10.14.3) ERROR { "message": "An error was thrown in afterAll\nUncaught TypeError: Cannot read property 'subscribe' of undefined thrown", "str": "An error was thrown in afterAll\nUncaught TypeError: Cannot read property 'subscribe' of undefined thrown" } Chrome 72.0.3626 (Mac OS X 10.14.3): Executed 131 of 148 (1 FAILED) ERROR (51.175 secs / 50.533 secs)
The other 50% of the time, all tests pass without any issues.
The major problem I have with this error message is that Jasmine is not telling me where the issue is, while if I write in any tests of mine e.g expect(true).toBe(false)
, then Jasmine tells me where and when expect(true).toBe(false)
failed.
How could I find where this error is coming from? Did anybody experience any inconsistency in Jasmine?
Thanks for all the help!
Upvotes: 1
Views: 6531
Reputation: 2455
Finally solved the issue after many hours of digging.
The error messages in the console started making more sense after the setting the random flag to false in karma.conf.js
.
module.exports = function(config) {
config.set({
client: {
jasmine: {
random: false
}
}
})
}
In our case, one of our tests were failing due to not properly handling an async call in one of the components. Removing that test fixed the inconsistency issue.
Even though the message in the console was still not able to pinpoint the originator of the error, it was at least able to show the component / test suite that the error came from.
Upvotes: 2