node/test/parallel/test-util-internal.js
Bryan English 324c82b1c9
test: use common.fixturesDir almost everywhere
Updating tests to use `common.fixturesDir` whenever possible/reasonable.
Left out things like tests for `path` and `require.resolve`.

PR-URL: https://github.com/nodejs/node/pull/6997
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-01-31 20:04:31 -05:00

33 lines
1.1 KiB
JavaScript

'use strict';
// Flags: --expose_internals
const common = require('../common');
const path = require('path');
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(path.join(common.fixturesDir, 'syntax', 'bad_syntax'));
} catch (err) {
arrowMessage = internalUtil.getHiddenValue(err, 'arrowMessage');
}
assert(/bad_syntax\.js:1/.test(arrowMessage));