• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    cb(null, '127.0.0.1', 100);
40  });
41
42  s.on('error', common.expectsError({
43    code: 'ERR_INVALID_ADDRESS_FAMILY',
44    host: 'localhost',
45    port: 0,
46    message: 'Invalid address family: 100 localhost:0'
47  }));
48}
49