-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from emberjs/unhandled-rejection
Update to QUnit 2.5.0
- Loading branch information
Showing
4 changed files
with
619 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!'); | ||
}); | ||
}); | ||
} | ||
}); |
Oops, something went wrong.