From 7984330657f95af9a8dd3e552de3230ed4424de1 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Sun, 21 Jan 2018 17:54:09 +0100 Subject: [PATCH] test: adds tests for vm invalid arguments --- test/parallel/test-vm-basic.js | 55 +++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-vm-basic.js b/test/parallel/test-vm-basic.js index 864c3553663a2c..3a74cb38d26402 100644 --- a/test/parallel/test-vm-basic.js +++ b/test/parallel/test-vm-basic.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const vm = require('vm'); @@ -69,3 +69,56 @@ assert.strictEqual(result, 'undefined'); const sandbox3 = {}; 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' +}); + +common.expectsError(() => { + vm.createContext({}, 'string'); +}, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "options" argument must be of type object. Received type string' +}); + +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' +});