| 1 |
const test = require('tape') |
| 2 |
const queueMicrotask = require('../') |
| 3 |
|
| 4 |
test('basic test', t => { |
| 5 |
t.plan(1) |
| 6 |
queueMicrotask(() => t.pass('function was called')) |
| 7 |
}) |
| 8 |
|
| 9 |
test('ensure correct ordering', t => { |
| 10 |
t.plan(3) |
| 11 |
|
| 12 |
let order = 0 |
| 13 |
|
| 14 |
queueMicrotask(() => { |
| 15 |
t.equal(++order, 1) |
| 16 |
queueMicrotask(() => t.equal(++order, 2)) |
| 17 |
}) |
| 18 |
|
| 19 |
setTimeout(() => t.equal(++order, 3), 0) |
| 20 |
}) |
| 21 |
|
| 22 |
test('error handling', t => { |
| 23 |
t.plan(2) |
| 24 |
|
| 25 |
process.on('uncaughtException', onUncaughtException) |
| 26 |
|
| 27 |
function onUncaughtException (err) { |
| 28 |
t.equal(err.message, 'some error') |
| 29 |
process.removeListener('uncaughtException', onUncaughtException) |
| 30 |
} |
| 31 |
|
| 32 |
queueMicrotask(() => { |
| 33 |
t.pass('function called') |
| 34 |
throw new Error('some error') |
| 35 |
}) |
| 36 |
}) |