diff --git a/lib/nodejs/serializer.js b/lib/nodejs/serializer.js index 448cb52e45..70640bc5b1 100644 --- a/lib/nodejs/serializer.js +++ b/lib/nodejs/serializer.js @@ -131,7 +131,11 @@ class SerializableEvent { */ constructor(eventName, originalValue, originalError) { if (!eventName) { - throw new Error('expected a non-empty `eventName` string argument'); + throw createInvalidArgumentTypeError( + 'Empty `eventName` string argument', + 'eventName', + 'string' + ); } /** * The event name. @@ -140,8 +144,10 @@ class SerializableEvent { this.eventName = eventName; const originalValueType = type(originalValue); if (originalValueType !== 'object' && originalValueType !== 'undefined') { - throw new Error( - `expected object, received [${originalValueType}]: ${originalValue}` + throw createInvalidArgumentTypeError( + `Expected object but received ${originalValueType}`, + 'originalValue', + 'object' ); } /** diff --git a/test/node-unit/serializer.spec.js b/test/node-unit/serializer.spec.js index 86848d90b4..0169338a05 100644 --- a/test/node-unit/serializer.spec.js +++ b/test/node-unit/serializer.spec.js @@ -88,22 +88,18 @@ describe('serializer', function() { describe('SerializableEvent', function() { describe('constructor', function() { describe('when called without `eventName`', function() { - it('should throw', function() { - expect( - () => new SerializableEvent(), - 'to throw', - /expected a non-empty `eventName`/ - ); + it('should throw "invalid arg value" error', function() { + expect(() => new SerializableEvent(), 'to throw', { + code: 'ERR_MOCHA_INVALID_ARG_TYPE' + }); }); }); describe('when called with a non-object `rawObject`', function() { - it('should throw', function() { - expect( - () => new SerializableEvent('blub', 'glug'), - 'to throw', - /expected object, received \[string\]/ - ); + it('should throw "invalid arg type" error', function() { + expect(() => new SerializableEvent('blub', 'glug'), 'to throw', { + code: 'ERR_MOCHA_INVALID_ARG_TYPE' + }); }); }); });