diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-03-19 13:33:46 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-03-25 01:45:37 +0100 |
commit | c6b6c92185316e13738e6fa931fdd5303e381e46 (patch) | |
tree | c38af9cd1a0a8cd6eeb459af3adee4dfd390fdc6 /test/parallel/test-vm-basic.js | |
parent | eeb57022e6bada13955a19b15232a9ee4fe9b465 (diff) | |
download | android-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.tar.gz android-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.tar.bz2 android-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.zip |
lib: always show ERR_INVALID_ARG_TYPE received part
This makes a effort to make sure all of these errors will actually
also show the received input.
On top of that it refactors a few tests for better maintainability.
It will also change the returned type to always be a simple typeof
instead of special handling null.
PR-URL: https://github.com/nodejs/node/pull/19445
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test/parallel/test-vm-basic.js')
-rw-r--r-- | test/parallel/test-vm-basic.js | 73 |
1 files changed, 27 insertions, 46 deletions
diff --git a/test/parallel/test-vm-basic.js b/test/parallel/test-vm-basic.js index 3a74cb38d2..bf1532cacc 100644 --- a/test/parallel/test-vm-basic.js +++ b/test/parallel/test-vm-basic.js @@ -71,54 +71,35 @@ const context2 = vm.createContext(sandbox3); assert.strictEqual(sandbox3, context2); // Test 6: invalid arguments -common.expectsError(() => { - vm.createContext({}, null); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options" argument must be of type object. Received type null' +[null, 'string'].forEach((input) => { + common.expectsError(() => { + vm.createContext({}, input); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "options" argument must be of type object. ' + + `Received type ${typeof input}` + }); }); -common.expectsError(() => { - vm.createContext({}, 'string'); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options" argument must be of type object. Received type string' +['name', 'origin'].forEach((propertyName) => { + common.expectsError(() => { + vm.createContext({}, { [propertyName]: null }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: `The "options.${propertyName}" property must be of type string. ` + + 'Received type object' + }); }); -common.expectsError(() => { - vm.createContext({}, { name: null }); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options.name" property must be of type string. ' + - 'Received type null' -}); - -common.expectsError(() => { - vm.createContext({}, { origin: null }); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options.origin" property must be of type string. ' + - 'Received type null' -}); - -common.expectsError(() => { - vm.runInNewContext('', {}, { contextName: null }); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options.contextName" property must be of type string. ' + - 'Received type null' -}); - -common.expectsError(() => { - vm.runInNewContext('', {}, { contextOrigin: null }); -}, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "options.contextOrigin" property must be of type string. ' + - 'Received type null' +['contextName', 'contextOrigin'].forEach((propertyName) => { + common.expectsError(() => { + vm.runInNewContext('', {}, { [propertyName]: null }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: `The "options.${propertyName}" property must be of type string. ` + + 'Received type object' + }); }); |