Skip to content

Instantly share code, notes, and snippets.

@alexmiddeleer
Last active May 5, 2017 18:25
Show Gist options
  • Save alexmiddeleer/baee64ad24ab4569c979a19bcc02d5d2 to your computer and use it in GitHub Desktop.
Save alexmiddeleer/baee64ad24ab4569c979a19bcc02d5d2 to your computer and use it in GitHub Desktop.
Why does the test fail if I wrap the catch in Ember.run?
// .... service boilerplate
doAsyncThing() {
return get(this, 'someService').postV2Request().catch((e) => {
// If I wrap this code in Ember.run, the tests fail after upgrading to Ember 2.13 from 2.3
let logError = new Error('foobar error');
this.reportError(logError);
throw(e);
});
}
// ... service boilerplate
test('doAsyncThing reports an error if there is one', function(assert) {
assert.expect(3);
let done = assert.async();
let deferred = RSVP.defer();
let apiService = mock({
postV2Request: sinon.stub().returns(deferred.promise)
});
let reportErrorStub = sinon.stub();
let service = this.subject({
apiService,
reportError: reportErrorStub
});
service.doAsyncThing('foo', 'bar', 'baz').catch(() => {
assert.ok(true, 'The exception is rethrown');
assert.ok(reportErrorStub.called, 'reportError was called');
assert.equal(reportErrorStub.args[0][0].message, 'foobar error', 'format of message is ok');
done();
});
deferred.reject();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment