2015-05-19 11:00:06 +00:00
|
|
|
'use strict';
|
2019-12-25 17:02:16 +00:00
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
2016-12-30 23:38:06 +00:00
|
|
|
const EventEmitter = require('events');
|
2019-01-21 19:45:55 +00:00
|
|
|
const util = require('util');
|
2015-05-07 21:09:31 +00:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const EE = new EventEmitter();
|
2015-05-07 21:09:31 +00:00
|
|
|
|
2019-12-25 17:02:16 +00:00
|
|
|
assert.throws(
|
2017-09-26 04:43:32 +00:00
|
|
|
() => EE.emit('error', 'Accepts a string'),
|
|
|
|
{
|
|
|
|
code: 'ERR_UNHANDLED_ERROR',
|
2019-12-25 17:02:16 +00:00
|
|
|
name: 'Error',
|
2022-11-22 23:03:33 +00:00
|
|
|
message: "Unhandled error. ('Accepts a string')",
|
2017-09-26 04:43:32 +00:00
|
|
|
}
|
|
|
|
);
|
2016-12-21 17:32:21 +00:00
|
|
|
|
2019-12-25 17:02:16 +00:00
|
|
|
assert.throws(
|
2017-09-26 04:43:32 +00:00
|
|
|
() => EE.emit('error', { message: 'Error!' }),
|
2019-01-21 19:45:55 +00:00
|
|
|
{
|
|
|
|
code: 'ERR_UNHANDLED_ERROR',
|
2019-12-25 17:02:16 +00:00
|
|
|
name: 'Error',
|
2022-11-22 23:03:33 +00:00
|
|
|
message: "Unhandled error. ({ message: 'Error!' })",
|
2019-01-21 19:45:55 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-25 17:02:16 +00:00
|
|
|
assert.throws(
|
2019-01-21 19:45:55 +00:00
|
|
|
() => EE.emit('error', {
|
|
|
|
message: 'Error!',
|
2022-11-22 23:03:33 +00:00
|
|
|
[util.inspect.custom]() { throw new Error(); },
|
2019-01-21 19:45:55 +00:00
|
|
|
}),
|
2017-09-26 04:43:32 +00:00
|
|
|
{
|
|
|
|
code: 'ERR_UNHANDLED_ERROR',
|
2019-12-25 17:02:16 +00:00
|
|
|
name: 'Error',
|
2022-11-22 23:03:33 +00:00
|
|
|
message: 'Unhandled error. ([object Object])',
|
2017-09-26 04:43:32 +00:00
|
|
|
}
|
|
|
|
);
|