29.7.0 • Published 5 months ago

jest-validate v29.7.0

Weekly downloads
12,328,501
License
MIT
Repository
github
Last release
5 months ago

jest-validate

Generic configuration validation tool that helps you with warnings, errors and deprecation messages as well as showing users examples of correct configuration.

npm install --save jest-validate

Usage

import {validate} from 'jest-validate';

validate((config: Object), (options: ValidationOptions)); // => {hasDeprecationWarnings: boolean, isValid: boolean}

Where ValidationOptions are:

type ValidationOptions = {
  comment?: string,
  condition?: (option: any, validOption: any) => boolean,
  deprecate?: (
    config: Object,
    option: string,
    deprecatedOptions: Object,
    options: ValidationOptions,
  ) => true,
  deprecatedConfig?: {[key: string]: Function},
  error?: (
    option: string,
    received: any,
    defaultValue: any,
    options: ValidationOptions,
  ) => void,
  exampleConfig: Object,
  title?: Title,
  unknown?: (
    config: Object,
    exampleConfig: Object,
    option: string,
    options: ValidationOptions,
  ) => void,
};

type Title = {|
  deprecation?: string,
  error?: string,
  warning?: string,
|};

exampleConfig is the only option required.

API

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.

Options

  • 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.
  • 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.

Examples

Minimal example:

validate(config, {exampleConfig});

Example with slight modifications:

validate(config, {
  comment: '  Documentation: http://custom-docs.com',
  deprecatedConfig,
  exampleConfig,
  title: {
    deprecation: 'Custom Deprecation',
    // leaving 'error' and 'warning' as default
  },
});

This will output:

Warning:

● Validation Warning:

  Unknown option transformx with value "<rootDir>/node_modules/babel-jest" was found.
  This is either a typing error or a user mistake. Fixing it will remove this message.

  Documentation: http://custom-docs.com

Error:

● Validation Error:

  Option transform must be of type:
    object
  but instead received:
    string

  Example:
  {
    "transform": {"^.+\\.js$": "<rootDir>/preprocessor.js"}
  }

  Documentation: http://custom-docs.com

Deprecation

Based on deprecatedConfig object with proper deprecation messages. Note custom title:

Custom Deprecation:

  Option scriptPreprocessor was replaced by transform, which support multiple preprocessors.

  Jest now treats your current configuration as:
  {
    "transform": {".*": "xxx"}
  }

  Please update your configuration.

  Documentation: http://custom-docs.com
jest-resolvejest-clijest-config@jest/corearchetype-libraryeasy-select-rnreact-native-bluetooth2killi8n-react-native-fast-imagespecify-importsbabel-specify-imports@icanpm/api-masterreact-native-template-rfbase@irisview/jest-cliairscanairscan-examplereact-native-esc-pos-sahaab@borisovart/atol-kkt-moduledeneme323112@translation/conf@ntt_app/react-native-custom-notificationreact-native-custom-text-hwjamesreact-native-covid-sdkgql_din_mod@olivervorasai/sliderreact-native-printer-brothersrn-pdf-reader-offlinereact-native-shekhar-bridge-testwilscanner@oiti/documentoscopy-react-native@mink-opn/build-tokensquoc-testreact-native-slider-kfplginexpand-react-bridgeluminos-ui-coresklif-ui-kitsklif-api@everything-registry/sub-chunk-1956jawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgp149-tablesklif-uireact-native-jawwy_samplegriffin-ui-librarynebula-http-resiliencycomposizetachyon-relay-buildtailwind-vector-effectsyncbackbasestest-library-123test-haptik-libtest-npm-jjmessiwonder-jest-configwontbreakwebchewoven-challenge-deploywifi_configuration_packageteapackage-tatespoorman297superset-plugin-chart-hello-world2supercluster-googlemaps-adapter-clonesstanikionespotify-ds-sestp-cdktestapatest-zeo-collecttestnpm_lmnsvelte-component-libtext-based-game-enginevision-camera-plugin-face-detectorvision-camera-plugin-scan-facesvision-camera-base64-resizedvcloudcam-playkit-js-hlsvalidate-pathvantiq-reactvue-axios-restvue-dev-clone@dormammuuuuu/json-helper@donapot/mylibtest@doxatest/jest-config@dskdavid/flash_cli@cryptocode99/token-lists@cs6/react-native-test-native-view-library@con-test/react-native-concent-common@damian.lnc/core@damruravihara/react-native-testing-package@cute-apocalypse/react-tree@corelmax/react-native-my2c2p-sdk@blueberry_muffins/email_library@rps-engine/core@praella/localisationist@percent/percent-api-hooks@poscredit/plugin-chart-boris@routebuddies/react-native-mapbox-navigationjest-repljest-runner-playwright-e2ejest-sonar-reporter-ext
30.0.0-alpha.7

5 months ago

30.0.0-alpha.6

11 months ago

30.0.0-alpha.5

1 year ago

30.0.0-alpha.4

1 year ago

30.0.0-alpha.3

1 year ago

30.0.0-alpha.2

2 years ago

30.0.0-alpha.1

2 years ago

29.7.0

2 years ago

29.6.3

2 years ago

29.6.0

2 years ago

29.6.1

2 years ago

29.6.2

2 years ago

29.4.1

2 years ago

29.4.2

2 years ago

29.4.3

2 years ago

29.4.0

2 years ago

29.5.0

2 years ago

29.2.0

3 years ago

29.2.1

3 years ago

29.2.2

3 years ago

29.3.1

3 years ago

29.0.1

3 years ago

29.0.2

3 years ago

29.0.3

3 years ago

29.0.0

3 years ago

29.1.0

3 years ago

29.1.2

3 years ago

28.1.3

3 years ago

28.1.1

3 years ago

29.0.0-alpha.6

3 years ago

29.0.0-alpha.4

3 years ago

29.0.0-alpha.3

3 years ago

29.0.0-alpha.0

3 years ago

29.0.0-alpha.1

3 years ago

28.1.0

3 years ago

28.0.0-alpha.9

3 years ago

28.0.0

3 years ago

28.0.1

3 years ago

28.0.2

3 years ago

28.0.0-alpha.8

3 years ago

28.0.0-alpha.7

3 years ago

28.0.0-alpha.6

3 years ago

28.0.0-alpha.5

3 years ago

27.5.0

3 years ago

27.5.1

3 years ago

27.4.6

4 years ago

27.4.0

4 years ago

27.4.1

4 years ago

27.4.2

4 years ago

28.0.0-alpha.4

3 years ago

28.0.0-alpha.3

3 years ago

28.0.0-alpha.0

3 years ago

28.0.0-alpha.2

3 years ago

28.0.0-alpha.1

3 years ago

27.3.0

4 years ago

27.3.1

4 years ago

27.2.5

4 years ago

27.2.4

4 years ago

27.2.3

4 years ago

27.2.2

4 years ago

27.2.0

4 years ago

27.1.1

4 years ago

27.1.0

4 years ago

27.0.6

4 years ago

27.0.2

4 years ago

27.0.0

4 years ago

27.0.1

4 years ago

27.0.0-next.11

4 years ago

27.0.0-next.10

4 years ago

27.0.0-next.9

4 years ago

27.0.0-next.8

4 years ago

27.0.0-next.7

4 years ago

27.0.0-next.6

4 years ago

27.0.0-next.5

4 years ago

27.0.0-next.3

4 years ago

27.0.0-next.1

5 years ago

27.0.0-next.0

5 years ago

26.6.2

5 years ago

26.6.1

5 years ago

26.6.0

5 years ago

26.5.3

5 years ago

26.5.2

5 years ago

26.5.0

5 years ago

26.4.2

5 years ago

26.4.0

5 years ago

26.3.0

5 years ago

26.2.0

5 years ago

26.1.0

5 years ago

26.0.1-alpha.0

5 years ago

26.0.1

5 years ago

26.0.0

5 years ago

26.0.0-alpha.2

5 years ago

26.0.0-alpha.1

5 years ago

26.0.0-alpha.0

5 years ago

25.5.0

5 years ago

25.4.0

5 years ago

25.3.0

5 years ago

25.2.6

5 years ago

25.2.1-alpha.2

5 years ago

25.2.3

5 years ago

25.2.1

5 years ago

25.2.1-alpha.1

5 years ago

25.2.0-alpha.86

5 years ago

25.2.0

5 years ago

25.1.0

5 years ago

25.0.0

6 years ago

24.9.0

6 years ago

24.8.0

6 years ago

24.7.0

6 years ago

24.6.0

6 years ago

24.5.0

6 years ago

24.4.0

6 years ago

24.3.1

6 years ago

24.3.0

6 years ago

24.2.0-alpha.0

6 years ago

24.0.0

6 years ago

24.0.0-alpha.16

6 years ago

24.0.0-alpha.15

6 years ago

24.0.0-alpha.13

6 years ago

24.0.0-alpha.12

6 years ago

24.0.0-alpha.11

6 years ago

24.0.0-alpha.10

6 years ago

24.0.0-alpha.9

7 years ago

24.0.0-alpha.8

7 years ago

24.0.0-alpha.7

7 years ago

24.0.0-alpha.6

7 years ago

24.0.0-alpha.5

7 years ago

24.0.0-alpha.4

7 years ago

24.0.0-alpha.2

7 years ago

24.0.0-alpha.1

7 years ago

24.0.0-alpha.0

7 years ago

23.6.0

7 years ago

23.5.0

7 years ago

23.4.0

7 years ago

23.3.0

7 years ago

23.2.0

7 years ago

23.0.1

7 years ago

23.0.0

7 years ago

23.0.0-charlie.4

7 years ago

23.0.0-charlie.3

7 years ago

22.4.4

7 years ago

23.0.0-charlie.2

7 years ago

23.0.0-charlie.1

7 years ago

23.0.0-charlie.0

7 years ago

23.0.0-beta.3r

7 years ago

23.0.0-alpha.3r

7 years ago

23.0.0-beta.2

7 years ago

23.0.0-beta.1

7 years ago

23.0.0-beta.0

7 years ago

23.0.0-alpha.7

7 years ago

23.0.0-alpha.6r

7 years ago

23.0.0-alpha.5r

7 years ago

23.0.0-alpha.5

7 years ago

23.0.0-alpha.4

7 years ago

23.0.0-alpha.2

7 years ago

22.4.3

7 years ago

23.0.0-alpha.1

7 years ago

23.0.0-alpha.0

7 years ago

22.4.2

7 years ago

22.4.1

7 years ago

22.4.0

7 years ago

22.2.2

7 years ago

22.2.0

7 years ago

22.1.2

7 years ago

22.1.0

7 years ago

22.0.6

7 years ago

22.0.5

7 years ago

22.0.3

8 years ago

22.0.2

8 years ago

22.0.1

8 years ago

22.0.0

8 years ago

21.3.0-beta.15

8 years ago

21.3.0-beta.14

8 years ago

21.3.0-beta.13

8 years ago

21.3.0-beta.12

8 years ago

21.3.0-beta.11

8 years ago

21.3.0-beta.10

8 years ago

21.3.0-beta.9

8 years ago

21.3.0-beta.8

8 years ago

21.3.0-beta.7

8 years ago

21.3.0-beta.6

8 years ago

21.3.0-beta.5

8 years ago

21.3.0-beta.4

8 years ago

21.3.0-beta.3

8 years ago

21.3.0-beta.2

8 years ago

21.3.0-beta.1

8 years ago

21.2.1

8 years ago

21.2.0

8 years ago

21.1.0

8 years ago

21.0.2

8 years ago

21.0.0

8 years ago

21.0.0-beta.1

8 years ago

21.0.0-alpha.2

8 years ago

21.0.0-alpha.1

8 years ago

20.1.0-echo.1

8 years ago

20.1.0-delta.5

8 years ago

20.1.0-delta.4

8 years ago

20.1.0-delta.3

8 years ago

20.1.0-delta.2

8 years ago

20.1.0-delta.1

8 years ago

20.1.0-chi.1

8 years ago

20.1.0-beta.1

8 years ago

20.1.0-alpha.3

8 years ago

20.1.0-alpha.2

8 years ago

20.1.0-alpha.1

8 years ago

20.0.3

8 years ago

20.0.2

8 years ago

20.0.1

8 years ago

20.0.0

8 years ago

19.0.2

8 years ago

19.0.0

8 years ago

18.2.0

8 years ago

18.1.0

8 years ago

0.0.0

8 years ago