node/test/parallel/test-next-tick-errors.js
Rich Trott 337d2dd381 test: implement consistent braces
This change is in preparation for lint enforcement of brace style.

PR-URL: https://github.com/nodejs/node/pull/8348
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2016-10-26 14:08:53 -04:00

36 lines
937 B
JavaScript

'use strict';
require('../common');
var assert = require('assert');
const order = [];
let exceptionHandled = false;
// This nextTick function will throw an error. It should only be called once.
// When it throws an error, it should still get removed from the queue.
process.nextTick(function() {
order.push('A');
// cause an error
what(); // eslint-disable-line no-undef
});
// This nextTick function should remain in the queue when the first one
// is removed. It should be called if the error in the first one is
// caught (which we do in this test).
process.nextTick(function() {
order.push('C');
});
process.on('uncaughtException', function() {
if (!exceptionHandled) {
exceptionHandled = true;
order.push('B');
} else {
// If we get here then the first process.nextTick got called twice
order.push('OOPS!');
}
});
process.on('exit', function() {
assert.deepEqual(['A', 'B', 'C'], order);
});