summaryrefslogtreecommitdiff
path: root/test/parallel/test-net-options-lookup.js
blob: f0e8b34c807df0811adcf831e94ac4d1e4808a56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
require('../common');
const assert = require('assert');
const net = require('net');

const expectedError = /^TypeError: "lookup" option should be a function$/;

['foobar', 1, {}, []].forEach((input) => connectThrows(input));

// Using port 0 as lookup is emitted before connecting.
function connectThrows(input) {
  const opts = {
    host: 'localhost',
    port: 0,
    lookup: input
  };

  assert.throws(() => {
    net.connect(opts);
  }, expectedError);
}

connectDoesNotThrow(() => {});

function connectDoesNotThrow(input) {
  const opts = {
    host: 'localhost',
    port: 0,
    lookup: input
  };

  assert.doesNotThrow(() => {
    net.connect(opts);
  });
}