1// Flags: --expose-internals 2'use strict'; 3 4require('../common'); 5const assert = require('assert'); 6const { validateOneOf } = require('internal/validators'); 7 8{ 9 // validateOneOf number incorrect. 10 const allowed = [2, 3]; 11 assert.throws(() => validateOneOf(1, 'name', allowed), { 12 code: 'ERR_INVALID_ARG_VALUE', 13 // eslint-disable-next-line quotes 14 message: `The argument 'name' must be one of: 2, 3. Received 1` 15 }); 16} 17 18{ 19 // validateOneOf number correct. 20 validateOneOf(2, 'name', [1, 2]); 21} 22 23{ 24 // validateOneOf string incorrect. 25 const allowed = ['b', 'c']; 26 assert.throws(() => validateOneOf('a', 'name', allowed), { 27 code: 'ERR_INVALID_ARG_VALUE', 28 // eslint-disable-next-line quotes 29 message: `The argument 'name' must be one of: 'b', 'c'. Received 'a'` 30 }); 31} 32 33{ 34 // validateOneOf string correct. 35 validateOneOf('two', 'name', ['one', 'two']); 36} 37 38{ 39 // validateOneOf Symbol incorrect. 40 const allowed = [Symbol.for('b'), Symbol.for('c')]; 41 assert.throws(() => validateOneOf(Symbol.for('a'), 'name', allowed), { 42 code: 'ERR_INVALID_ARG_VALUE', 43 // eslint-disable-next-line quotes 44 message: `The argument 'name' must be one of: Symbol(b), Symbol(c). ` + 45 'Received Symbol(a)' 46 }); 47} 48 49{ 50 // validateOneOf Symbol correct. 51 const allowed = [Symbol.for('b'), Symbol.for('c')]; 52 validateOneOf(Symbol.for('b'), 'name', allowed); 53} 54