Skip to content

Commit

Permalink
Add failing tests for unhandled promise rejections.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Jan 17, 2018
1 parent a67d4b0 commit 1d70169
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
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
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 1d70169

Please sign in to comment.