mirror of
https://github.com/nodejs/node.git
synced 2026-11-15 10:36:53 -05:00
Refs: https://eslint.org/blog/2023/10/deprecating-formatting-rules/ PR-URL: https://github.com/nodejs/node/pull/50714 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const { validateOneOf } = require('internal/validators');
|
|
|
|
{
|
|
// validateOneOf number incorrect.
|
|
const allowed = [2, 3];
|
|
assert.throws(() => validateOneOf(1, 'name', allowed), {
|
|
code: 'ERR_INVALID_ARG_VALUE',
|
|
// eslint-disable-next-line @stylistic/js/quotes
|
|
message: `The argument 'name' must be one of: 2, 3. Received 1`
|
|
});
|
|
}
|
|
|
|
{
|
|
// validateOneOf number correct.
|
|
validateOneOf(2, 'name', [1, 2]);
|
|
}
|
|
|
|
{
|
|
// validateOneOf string incorrect.
|
|
const allowed = ['b', 'c'];
|
|
assert.throws(() => validateOneOf('a', 'name', allowed), {
|
|
code: 'ERR_INVALID_ARG_VALUE',
|
|
// eslint-disable-next-line @stylistic/js/quotes
|
|
message: `The argument 'name' must be one of: 'b', 'c'. Received 'a'`
|
|
});
|
|
}
|
|
|
|
{
|
|
// validateOneOf string correct.
|
|
validateOneOf('two', 'name', ['one', 'two']);
|
|
}
|
|
|
|
{
|
|
// validateOneOf Symbol incorrect.
|
|
const allowed = [Symbol.for('b'), Symbol.for('c')];
|
|
assert.throws(() => validateOneOf(Symbol.for('a'), 'name', allowed), {
|
|
code: 'ERR_INVALID_ARG_VALUE',
|
|
// eslint-disable-next-line @stylistic/js/quotes
|
|
message: `The argument 'name' must be one of: Symbol(b), Symbol(c). ` +
|
|
'Received Symbol(a)'
|
|
});
|
|
}
|
|
|
|
{
|
|
// validateOneOf Symbol correct.
|
|
const allowed = [Symbol.for('b'), Symbol.for('c')];
|
|
validateOneOf(Symbol.for('b'), 'name', allowed);
|
|
}
|