1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const assert = require('assert'); 7const http2 = require('http2'); 8const { inspect } = require('util'); 9 10// Check if correct errors are emitted when wrong type of data is passed 11// to certain options of ClientHttp2Session request method 12 13const optionsToTest = { 14 endStream: 'boolean', 15 weight: 'number', 16 parent: 'number', 17 exclusive: 'boolean', 18 silent: 'boolean' 19}; 20 21const types = { 22 boolean: true, 23 function: () => {}, 24 number: 1, 25 object: {}, 26 array: [], 27 null: null, 28 symbol: Symbol('test') 29}; 30 31const server = http2.createServer(common.mustNotCall()); 32 33server.listen(0, common.mustCall(() => { 34 const port = server.address().port; 35 const client = http2.connect(`http://localhost:${port}`); 36 37 client.on('connect', () => { 38 Object.keys(optionsToTest).forEach((option) => { 39 Object.keys(types).forEach((type) => { 40 if (type === optionsToTest[option]) 41 return; 42 43 assert.throws( 44 () => client.request({ 45 ':method': 'CONNECT', 46 ':authority': `localhost:${port}` 47 }, { 48 [option]: types[type] 49 }), { 50 name: 'TypeError', 51 code: 'ERR_INVALID_OPT_VALUE', 52 message: `The value "${inspect(types[type])}" is invalid ` + 53 `for option "${option}"` 54 }); 55 }); 56 }); 57 server.close(); 58 client.close(); 59 }); 60})); 61