Skip to content

Commit

Permalink
[BUGFIX] Changed backburner's error handler to use dispatchError in…
Browse files Browse the repository at this point in the history
…stead of `onError`. This is so that backburner errors can be caught by the `Test.adapter`. Fixes emberjs#14864.
  • Loading branch information
Wesley Workman committed Feb 1, 2017
1 parent db34fc4 commit 196442d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/ember-metal/lib/error_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export function dispatchError(error) {
}

// allows testing adapter to override dispatch
export function getDispatchOverride() {
return dispatchOverride;
}
export function setDispatchOverride(handler) {
dispatchOverride = handler;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-metal/lib/run_loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GUID_KEY } from 'ember-utils';
import { assert } from './debug';
import { isTesting } from './testing';
import {
getOnerror,
dispatchError,
setOnerror
} from './error_handler';
import {
Expand All @@ -21,7 +21,7 @@ function onEnd(current, next) {

const onErrorTarget = {
get onerror() {
return getOnerror();
return dispatchError;
},
set onerror(handler) {
return setOnerror(handler);
Expand Down
10 changes: 9 additions & 1 deletion packages/ember-metal/tests/run_loop/onerror_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import run from '../../run_loop';
import { setOnerror, getOnerror } from '../../error_handler';
import { setOnerror, getOnerror, setDispatchOverride, getDispatchOverride } from '../../error_handler';
import { isTesting, setTesting } from '../../testing';

QUnit.module('system/run_loop/onerror_test');

Expand All @@ -23,13 +24,20 @@ QUnit.test('With Ember.onerror undefined, errors in Ember.run are thrown', funct
QUnit.test('With Ember.onerror set, errors in Ember.run are caught', function () {
let thrown = new Error('Boom!');
let original = getOnerror();
let originalDispatchOverride = getDispatchOverride();
let originalIsTesting = isTesting();

let caught;
setOnerror(error => { caught = error; });
setDispatchOverride(null);
setTesting(false);

try {
run(() => { throw thrown; });
} finally {
setOnerror(original);
setDispatchOverride(originalDispatchOverride);
setTesting(originalIsTesting);
}

deepEqual(caught, thrown);
Expand Down
23 changes: 20 additions & 3 deletions packages/ember-testing/tests/adapters_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ QUnit.module('ember-testing Adapters', {
originalQUnit = window.QUnit;
},
teardown() {
run(App, App.destroy);
App.removeTestHelpers();
App = null;
if (App) {
run(App, App.destroy);
App.removeTestHelpers();
App = null;
}

Test.adapter = originalAdapter;
window.QUnit = originalQUnit;
Expand Down Expand Up @@ -68,3 +70,18 @@ QUnit.test('Adapter is used by default (if QUnit is not available)', function()
ok(Test.adapter instanceof Adapter);
ok(!(Test.adapter instanceof QUnitAdapter));
});

QUnit.test('With Ember.Test.adapter set, errors in Ember.run are caught', function () {
let thrown = new Error('Boom!');

let caught;
Test.adapter = QUnitAdapter.create({
exception(error) {
caught = error;
}
});

run(() => { throw thrown; });

deepEqual(caught, thrown);
});

0 comments on commit 196442d

Please sign in to comment.