code-corps/ember-stripe-service

Cannot test failure modes

Opened this issue · 3 comments

See emberjs/ember.js#11469

Ember's default Promise.on('error') hook causes the current test to fail if it ever encounters a reject({ anything: "here" }). Because this library uses reject to indicate that the update failed, I can't write a test that asserts that I show an appropriate error message in case of failure.

I think this should be changed in Ember, but if they're going to hold firm, we should probably change it here.

In the meantime, one solution that @iezer came up with was to wrap the result in Ember.Error, which bypasses the fail test on promise rejection logic:

if (response.error) {
  Ember.run(null, reject, new Ember.Error(response.code));
}

Edit: this does not work. We had something else disguising the problem.

@jamesarosen ah, I remember this well. I think I opened the issue in ember-simple-auth that led to that chain.

What's your proposed solution for this right now? It's been over a year since my head was wrapped around that problem and haven't encountered it since.

Meanwhile, it looks like you may have made significant progress in your understanding of the problem/solution based on that thread.

The fallout of that Ember issue was that the core team added some tests to ensure that a rejected promise doesn't fail the tests, but an uncaught rejected promise does. So the application code should somehow account for the possible rejection.