summaryrefslogtreecommitdiff
path: root/test/parallel/test-util-internal.js
blob: 9ab883ec8b6dcdbbf52d045f561ad8823f1bc05a (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
'use strict';
// Flags: --expose_internals

const common = require('../common');
const assert = require('assert');
const internalUtil = require('internal/util');

function getHiddenValue(obj, name) {
  return function() {
    internalUtil.getHiddenValue(obj, name);
  };
}

assert.throws(getHiddenValue(), /obj must be an object/);
assert.throws(getHiddenValue(null, 'foo'), /obj must be an object/);
assert.throws(getHiddenValue(undefined, 'foo'), /obj must be an object/);
assert.throws(getHiddenValue('bar', 'foo'), /obj must be an object/);
assert.throws(getHiddenValue(85, 'foo'), /obj must be an object/);
assert.throws(getHiddenValue({}), /name must be a string/);
assert.throws(getHiddenValue({}, null), /name must be a string/);
assert.throws(getHiddenValue({}, []), /name must be a string/);
assert.deepEqual(internalUtil.getHiddenValue({}, 'foo'), undefined);

let arrowMessage;

try {
  require('../fixtures/syntax/bad_syntax');
} catch (err) {
  arrowMessage = internalUtil.getHiddenValue(err, 'arrowMessage');
}

assert(/bad_syntax\.js:1/.test(arrowMessage));