Skip to content

Commit

Permalink
[BUGFIX lts] Add tests for various permutations of error handler setup.
Browse files Browse the repository at this point in the history
Known permutations:

* Testing
  * With `Ember.onerror`
    * Sync Backburner (`run` and `run.join`)
    * Async Backburner (`run.later`, `run.next`)
    * RSVP
  * Without `Ember.onerror`
    * Sync Backburner (`run` and `run.join`)
    * Async Backburner (`run.later`, `run.next`)
    * RSVP
* Development / Production
  * With `Ember.onerror`
    * Sync Backburner (`run` and `run.join`)
    * Async Backburner (`run.later`, `run.next`)
    * RSVP
  * Without `Ember.onerror`
    * Sync Backburner (`run` and `run.join`)
    * Async Backburner (`run.later`, `run.next`)
    * RSVP

This commit adds tests for all scenarios.

(cherry picked from commit 1d37ba6)
  • Loading branch information
rwjblue committed Nov 29, 2017
1 parent d10f638 commit cfd6881
Show file tree
Hide file tree
Showing 2 changed files with 421 additions and 29 deletions.
19 changes: 13 additions & 6 deletions packages/ember-testing/tests/adapters_test.js
Expand Up @@ -4,12 +4,13 @@ import Adapter from '../adapters/adapter';
import QUnitAdapter from '../adapters/qunit';
import { Application as EmberApplication } from 'ember-application';

var App, originalAdapter, originalQUnit;
var App, originalAdapter, originalQUnit, originalWindowOnerror;

QUnit.module('ember-testing Adapters', {
setup() {
originalAdapter = Test.adapter;
originalQUnit = window.QUnit;
originalWindowOnerror = window.onerror;
},
teardown() {
if (App) {
Expand All @@ -20,6 +21,7 @@ QUnit.module('ember-testing Adapters', {

Test.adapter = originalAdapter;
window.QUnit = originalQUnit;
window.onerror = originalWindowOnerror;
}
});

Expand Down Expand Up @@ -71,17 +73,22 @@ QUnit.test('Adapter is used by default (if QUnit is not available)', function()
ok(!(Test.adapter instanceof QUnitAdapter));
});

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

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

run(() => { throw thrown; });
try {
run(() => { throw thrown; });
} catch(e) {
caughtInCatch = e;
}

deepEqual(caught, thrown);
assert.equal(caughtInAdapter, undefined, 'test adapter should never receive synchronous errors');
assert.equal(caughtInCatch, thrown, 'a "normal" try/catch should catch errors in sync run');
});

0 comments on commit cfd6881

Please sign in to comment.