Skip to content

Commit

Permalink
Merge pull request #306 from emberjs/unhandled-rejection
Browse files Browse the repository at this point in the history
Update to QUnit 2.5.0
  • Loading branch information
rwjblue committed Jan 17, 2018
2 parents a67d4b0 + c641283 commit a3c95ae
Show file tree
Hide file tree
Showing 4 changed files with 619 additions and 46 deletions.
2 changes: 1 addition & 1 deletion addon-test-support/ember-qunit/adapter.js
Expand Up @@ -15,7 +15,7 @@ function unhandledRejectionAssertion(current, error) {
source = 'unknown source';
}

current.pushResult({
current.assert.pushResult({
result: false,
actual: false,
expected: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -33,7 +33,7 @@
"common-tags": "^1.4.0",
"ember-cli-babel": "^6.3.0",
"ember-cli-test-loader": "^2.2.0",
"qunit": "^2.4.1"
"qunit": "^2.5.0"
},
"devDependencies": {
"ember-cli": "~2.15.1",
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/unhandled-rejection-test.js
@@ -0,0 +1,45 @@
import { Promise as RSVPPromise } from 'rsvp';
import { module, test } from 'qunit';

const HAS_NATIVE_PROMISE = typeof Promise !== 'undefined';
const HAS_UNHANDLED_REJECTION_HANDLER = 'onunhandledrejection' in window;

module('unhandle promise rejections', function(hooks) {
hooks.beforeEach(function(assert) {
let originalPushResult = assert.pushResult;
assert.pushResult = function(resultInfo) {
// Inverts the result so we can test failing assertions
resultInfo.result = !resultInfo.result;
resultInfo.message = `Failed: ${resultInfo.message}`;
originalPushResult(resultInfo);
};
});

test('RSVP promises cause an unhandled rejection', function(assert) {
let done = assert.async();

// ensure we do not exit this test until the assertion has happened
setTimeout(done, 10);

new RSVPPromise(resolve => {
setTimeout(resolve);
}).then(function() {
throw new Error('whoops!');
});
});

if (HAS_NATIVE_PROMISE && HAS_UNHANDLED_REJECTION_HANDLER) {
test('native promises cause an unhandled rejection', function(assert) {
let done = assert.async();

// ensure we do not exit this test until the assertion has happened
setTimeout(done, 10);

new self.Promise(resolve => {
setTimeout(resolve);
}).then(function() {
throw new Error('whoops!');
});
});
}
});

0 comments on commit a3c95ae

Please sign in to comment.