Skip to content

Commit

Permalink
[tests] add basic unhandled rejection tracking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Feb 18, 2016
1 parent 3568fe3 commit 4322de6
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions tests/library.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions tests/library/es6.promise.ls
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,35 @@ if PROTO
assert.ok p3 instanceof SubPromise
# check the async values
p3.then assert.async!, -> assert.ok it, no

test 'Unhandled rejection tracking' (assert)!->
done = no
start = assert.async!
Promise.reject(43).catch !->
$promise = Promise.reject 42
if process?
assert.expect 3
process.on \unhandledRejection, onunhandledrejection = (reason, promise)!->
assert.same promise, $promise, 'unhandledRejection, promise'
assert.same reason, 42, 'unhandledRejection, reason'
$promise.catch !->
process.removeListener \unhandledRejection, onunhandledrejection
process.on \rejectionHandled, onrejectionhandled = (promise)!->
assert.same promise, $promise, 'rejectionHandled, promise'
process.removeListener \rejectionHandled, onrejectionhandled
done or start!
done := on
else
assert.expect 4
global.onunhandledrejection = !->
assert.same it.promise, $promise, 'onunhandledrejection, promise'
assert.same it.reason, 42, 'onunhandledrejection, reason'
global.onunhandledrejection = null
$promise.catch !->
global.onrejectionhandled = !->
assert.same it.promise, $promise, 'onrejectionhandled, promise'
assert.same it.reason, 42, 'onrejectionhandled, reason'
global.onrejectionhandled = null
done or start!
done := on
setTimeout (!-> done or start!), 1e3
40 changes: 40 additions & 0 deletions tests/tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions tests/tests/es6.promise.ls
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,35 @@ if PROTO
assert.ok p3 instanceof SubPromise
# check the async values
p3.then assert.async!, -> assert.ok it, no

test 'Unhandled rejection tracking' (assert)!->
done = no
start = assert.async!
Promise.reject(43).catch !->
$promise = Promise.reject 42
if process?
assert.expect 3
process.on \unhandledRejection, onunhandledrejection = (reason, promise)!->
assert.same promise, $promise, 'unhandledRejection, promise'
assert.same reason, 42, 'unhandledRejection, reason'
$promise.catch !->
process.removeListener \unhandledRejection, onunhandledrejection
process.on \rejectionHandled, onrejectionhandled = (promise)!->
assert.same promise, $promise, 'rejectionHandled, promise'
process.removeListener \rejectionHandled, onrejectionhandled
done or start!
done := on
else
assert.expect 4
global.onunhandledrejection = !->
assert.same it.promise, $promise, 'onunhandledrejection, promise'
assert.same it.reason, 42, 'onunhandledrejection, reason'
global.onunhandledrejection = null
$promise.catch !->
global.onrejectionhandled = !->
assert.same it.promise, $promise, 'onrejectionhandled, promise'
assert.same it.reason, 42, 'onrejectionhandled, reason'
global.onrejectionhandled = null
done or start!
done := on
setTimeout (!-> done or start!), 1e3

0 comments on commit 4322de6

Please sign in to comment.