1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const net = require('net'); 5 6['foobar', 1, {}, []].forEach((input) => connectThrows(input)); 7 8// Using port 0 as lookup is emitted before connecting. 9function connectThrows(input) { 10 const opts = { 11 host: 'localhost', 12 port: 0, 13 lookup: input 14 }; 15 16 assert.throws(() => { 17 net.connect(opts); 18 }, { 19 code: 'ERR_INVALID_ARG_TYPE', 20 name: 'TypeError' 21 }); 22} 23 24connectDoesNotThrow(() => {}); 25 26function connectDoesNotThrow(input) { 27 const opts = { 28 host: 'localhost', 29 port: 0, 30 lookup: input 31 }; 32 33 return net.connect(opts); 34} 35 36{ 37 // Verify that an error is emitted when an invalid address family is returned. 38 const s = connectDoesNotThrow((host, options, cb) => { 39 if (options.all) { 40 cb(null, [{ address: '127.0.0.1', family: 100 }]); 41 } else { 42 cb(null, '127.0.0.1', 100); 43 } 44 }); 45 46 s.on('error', common.expectsError({ 47 code: 'ERR_INVALID_ADDRESS_FAMILY', 48 host: 'localhost', 49 port: 0, 50 message: 'Invalid address family: 100 localhost:0' 51 })); 52} 53