scotch-angular-testing icon indicating copy to clipboard operation
scotch-angular-testing copied to clipboard

2 Testing failing - Possibly unhandled rejection: {"detail":"Not found."} thrown

Open jeffro94 opened this issue 8 years ago • 7 comments

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

  1. 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 avatar Dec 13 '16 19:12 jeffro94

@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 avatar Dec 17 '16 23:12 atom-morgan

@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

ldmcdaniel avatar Dec 30 '16 23:12 ldmcdaniel

@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.

atom-morgan avatar Dec 31 '16 16:12 atom-morgan

given the change that was added to ui-router.

To be clear, this was a change to angular.js, not ui-router 👍

christopherthielen avatar Jan 07 '17 17:01 christopherthielen

Gotcha! Thank you for clarifying.

atom-morgan avatar Jan 07 '17 19:01 atom-morgan

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 avatar Jul 10 '17 05:07 modmac

@modmac Thanks, that fixed it for me:

  .config(['$qProvider', function($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
  }]);

apdavison avatar Nov 14 '17 20:11 apdavison