UNPKG

1.33 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.getValues = getValues;
7exports.multipleValidOptions = multipleValidOptions;
8exports.validationCondition = validationCondition;
9/**
10 * Copyright (c) Meta Platforms, Inc. and affiliates.
11 *
12 * This source code is licensed under the MIT license found in the
13 * LICENSE file in the root directory of this source tree.
14 */
15
16const toString = Object.prototype.toString;
17const MULTIPLE_VALID_OPTIONS_SYMBOL = Symbol('JEST_MULTIPLE_VALID_OPTIONS');
18function validationConditionSingle(option, validOption) {
19 return (
20 option === null ||
21 option === undefined ||
22 (typeof option === 'function' && typeof validOption === 'function') ||
23 toString.call(option) === toString.call(validOption)
24 );
25}
26function getValues(validOption) {
27 if (
28 Array.isArray(validOption) &&
29 // @ts-expect-error: no index signature
30 validOption[MULTIPLE_VALID_OPTIONS_SYMBOL]
31 ) {
32 return validOption;
33 }
34 return [validOption];
35}
36function validationCondition(option, validOption) {
37 return getValues(validOption).some(e => validationConditionSingle(option, e));
38}
39function multipleValidOptions(...args) {
40 const options = [...args];
41 // @ts-expect-error: no index signature
42 options[MULTIPLE_VALID_OPTIONS_SYMBOL] = true;
43 return options;
44}