Gathering detailed insights and metrics for jest-validate
Gathering detailed insights and metrics for jest-validate
Gathering detailed insights and metrics for jest-validate
Gathering detailed insights and metrics for jest-validate
@html-validate/jest-config
Jest sharable preset used by the various HTML-validate packages
@types/jest-validate
Stub TypeScript definitions entry for jest-validate, which provides its own types definitions
@jsdotlua/jest-validate
@html-validate/eslint-config-jest
Eslint sharable config used by the various HTML-validate packages
npm install jest-validate
Typescript
Module System
Min. Node Version
Node Version
NPM Version
98.4
Supply Chain
98.4
Quality
89.8
Maintenance
100
Vulnerability
100
License
v30.0.0-alpha.7
Published on 30 Jan 2025
v30.0.0-alpha.6
Published on 08 Aug 2024
v30.0.0-alpha.5
Published on 30 May 2024
v30.0.0-alpha.4
Published on 12 May 2024
v30.0.0-alpha.3
Published on 20 Feb 2024
v30.0.0-alpha.2
Published on 16 Nov 2023
TypeScript (79.06%)
JavaScript (20.28%)
CSS (0.56%)
Prolog (0.08%)
Shell (0.01%)
Handlebars (0.01%)
Total Downloads
5,172,539,760
Last Day
4,956,639
Last Week
22,402,487
Last Month
101,236,570
Last Year
1,336,404,998
44,450 Stars
7,303 Commits
6,491 Forks
560 Watching
7 Branches
1,551 Contributors
Minified
Minified + Gzipped
Latest Version
29.7.0
Package Id
jest-validate@29.7.0
Unpacked Size
28.06 kB
Size
7.56 kB
File Count
15
NPM Version
lerna/1.13.0/node@v18.17.1+arm64 (darwin)
Node Version
18.17.1
Publised On
12 Sept 2023
Cumulative downloads
Total Downloads
Last day
-4.8%
4,956,639
Compared to previous day
Last week
-15.2%
22,402,487
Compared to previous week
Last month
4.4%
101,236,570
Compared to previous month
Last year
8%
1,336,404,998
Compared to previous year
1
Generic configuration validation tool that helps you with warnings, errors and deprecation messages as well as showing users examples of correct configuration.
1npm install --save jest-validate
1import {validate} from 'jest-validate'; 2 3validate(config, validationOptions); // => {hasDeprecationWarnings: boolean, isValid: boolean}
Where ValidationOptions
are:
1type ValidationOptions = { 2 comment?: string; 3 condition?: (option: unknown, validOption: unknown) => boolean; 4 deprecate?: ( 5 config: Record<string, unknown>, 6 option: string, 7 deprecatedOptions: DeprecatedOptions, 8 options: ValidationOptions, 9 ) => boolean; 10 deprecatedConfig?: DeprecatedOptions; 11 error?: ( 12 option: string, 13 received: unknown, 14 defaultValue: unknown, 15 options: ValidationOptions, 16 path?: Array<string>, 17 ) => void; 18 exampleConfig: Record<string, unknown>; 19 recursive?: boolean; 20 recursiveBlacklist?: Array<string>; 21 recursiveDenylist?: Array<string>; 22 title?: Title; 23 unknown?: ( 24 config: Record<string, unknown>, 25 exampleConfig: Record<string, unknown>, 26 option: string, 27 options: ValidationOptions, 28 path?: Array<string>, 29 ) => void; 30}; 31 32type Title = { 33 deprecation?: string; 34 error?: string; 35 warning?: string; 36};
exampleConfig
is the only option required.
By default jest-validate
will print generic warning and error messages. You can however customize this behavior by providing options: ValidationOptions
object as a second argument:
Almost anything can be overwritten to suite your needs.
recursiveDenylist
– optional array of string keyPaths that should be excluded from deep (recursive) validation.comment
– optional string to be rendered below error/warning message.condition
– an optional function with validation condition.deprecate
, error
, unknown
– optional functions responsible for displaying warning and error messages.deprecatedConfig
– optional object with deprecated config keys.exampleConfig
– the only required option with configuration against which you'd like to test.recursive
- optional boolean determining whether recursively compare exampleConfig
to config
(default: true
).title
– optional object of titles for errors and messages.You will find examples of condition
, deprecate
, error
, unknown
, and deprecatedConfig
inside source of this repository, named respectively.
exampleConfig
should be an object with key/value pairs that contain an example of a valid value for each key. A configuration value is considered valid when:
string
, number
, array
, boolean
, function
, or object
null
or undefined
MultipleValidOptions(...)
The last condition is a special syntax that allows validating where more than one type is permissible; see example below. It's acceptable to have multiple values of the same type in the example, so you can also use this syntax to provide more than one example. When a validation failure occurs, the error message will show all other values in the array as examples.
Minimal example:
1validate(config, {exampleConfig});
Example with slight modifications:
1validate(config, { 2 comment: ' Documentation: http://custom-docs.com', 3 deprecatedConfig, 4 exampleConfig, 5 title: { 6 deprecation: 'Custom Deprecation', 7 // leaving 'error' and 'warning' as default 8 }, 9});
This will output:
1● Validation Warning: 2 3 Unknown option transformx with value "<rootDir>/node_modules/babel-jest" was found. 4 This is either a typing error or a user mistake. Fixing it will remove this message. 5 6 Documentation: http://custom-docs.com
1● Validation Error: 2 3 Option transform must be of type: 4 object 5 but instead received: 6 string 7 8 Example: 9 { 10 "transform": { 11 "\\.js$": "<rootDir>/preprocessor.js" 12 } 13 } 14 15 Documentation: http://custom-docs.com
1import {multipleValidOptions} from 'jest-validate'; 2 3validate(config, { 4 // `bar` will accept either a string or a number 5 bar: multipleValidOptions('string is ok', 2), 6});
1● Validation Error: 2 3 Option foo must be of type: 4 string or number 5 but instead received: 6 array 7 8 Example: 9 { 10 "bar": "string is ok" 11 } 12 13 or 14 15 { 16 "bar": 2 17 } 18 19 Documentation: http://custom-docs.com
Based on deprecatedConfig
object with proper deprecation messages. Note custom title:
1Custom Deprecation: 2 3 Option scriptPreprocessor was replaced by transform, which support multiple preprocessors. 4 5 Jest now treats your current configuration as: 6 { 7 "transform": {".*": "xxx"} 8 } 9 10 Please update your configuration. 11 12 Documentation: http://custom-docs.com
1import {validate} from 'jest-validate'; 2 3validateCLIOptions(argv, {...allowedOptions, deprecatedOptions});
If argv
contains a deprecated option that is not specifid in allowedOptions
, validateCLIOptions
will throw an error with the message specified in the deprecatedOptions
config:
1● collectCoverageOnlyFrom: 2 3 Option "collectCoverageOnlyFrom" was replaced by "collectCoverageFrom" 4 5 CLI Options Documentation: https://jestjs.io/docs/en/cli.html
If the deprecation option is still listed in the allowedOptions
config, then validateCLIOptions
will print the warning wihout throwing an error.
No vulnerabilities found.
No security vulnerabilities found.