Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Changed backburner's error handler to use dispatchError instead of onError #14898

Merged
merged 1 commit into from
Feb 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});