scotch-angular-testing
scotch-angular-testing copied to clipboard
2 Testing failing - Possibly unhandled rejection: {"detail":"Not found."} thrown
First, thanks a lot for creating these tutorials - I am almost done with part 2 and found they are really helpful.
When doing an npm install and karma start, 2 of the tests are failing due to an apparent bug with angular 1.5.9+ and ui-router. See here: https://github.com/angular-ui/ui-router/issues/2889
- should return a 404 when called with an invalid name Pokemon factory findByName() Possibly unhandled rejection: {"detail":"Not found."} thrown
You can resolve the the issue by setting the angular version to 1.5.8 in the package.json.
It's not clear though whether the way this project is handling the rejections is wrong or could be improved? Is there a more proper way to do it where this wouldn't be an issue?
@jeffro94 Thank you. I'm happy to hear you found the tutorials helpful. I looked into this today and I'm not 100% sure why it's happening. Thank you for linking to the ui-router
issue as well. I went through that and a few other issues to track down why this is happening and what changes need to be made to fix this.
Unless I've just been handling rejections incorrectly this entire time (I don't believe I have been) I don't think this was really something that could have been prevented. It seems to be related to this addition which is stated as a "BREAKING CHANGE".
I'll continue to look into this and wait to hear back on my question in your linked issue and we can go from there.
@atom-morgan: I am having the same issue and error as @jeffro94. I am not sure what to do, but I would love to finish the tutorial. Any ideas would be great. Here is my repo until this point in the project: https://github.com/ldmcdaniel/testing-angularJS-with-jasmine-karma.git
@jeffro94 and @ldmcdaniel,
I took a suggestion from @christopherthielen's comment here and added a new testing method to use when rejecting promise responses. I just submitted a PR with a fix for this if you don't mind letting me know what you think.
It's not my ideal solution but I don't see how it could have been handled any better given the change that was added to ui-router. Others in the thread have suggested it was an issue in their own code but I believe we're catch()
ing the responses as we should be.
given the change that was added to ui-router.
To be clear, this was a change to angular.js, not ui-router 👍
Gotcha! Thank you for clarifying.
Problem appears with AngularJS >= 1.6.
Try using $qProvider.errorOnUnhandledRejections(false)
on api.pokemon module config.
https://docs.angularjs.org/api/ng/provider/$qProvider
@modmac Thanks, that fixed it for me:
.config(['$qProvider', function($qProvider) {
$qProvider.errorOnUnhandledRejections(false);
}]);