mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
feat(jest-validate): initial commit
This commit is contained in:
parent
0a02fbe82a
commit
e8bbb05940
95
types/jest-validate/index.d.ts
vendored
Normal file
95
types/jest-validate/index.d.ts
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
// Type definitions for jest-validate 21.0
|
||||
// Project: https://github.com/facebook/jest/tree/master/packages/jest-validate
|
||||
// Definitions by: Ika <https://github.com/ikatyang>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export class ValidationError extends Error {
|
||||
name: string;
|
||||
message: string;
|
||||
constructor(name: string, message: string, comment?: string);
|
||||
}
|
||||
|
||||
export function createDidYouMeanMessage(
|
||||
unrecognized: string,
|
||||
allowedOptions: string[]
|
||||
): string;
|
||||
|
||||
export function format(value: any): string;
|
||||
|
||||
export function logValidationWarning(
|
||||
name: string,
|
||||
message: string,
|
||||
commant?: string
|
||||
): void;
|
||||
|
||||
export interface Title {
|
||||
deprecation?: string;
|
||||
error?: string;
|
||||
warning?: string;
|
||||
}
|
||||
|
||||
export interface DeprecatedConfig {
|
||||
[key: string]: (config: object) => string;
|
||||
}
|
||||
|
||||
export interface ValidationOptions {
|
||||
/**
|
||||
* optional string to be rendered below error/warning message.
|
||||
*/
|
||||
comment?: string;
|
||||
/**
|
||||
* an optional function with validation condition.
|
||||
*/
|
||||
condition?(value: any, exampleValue: any): boolean;
|
||||
/**
|
||||
* optional object with deprecated config keys.
|
||||
*/
|
||||
deprecatedConfig?: DeprecatedConfig;
|
||||
/**
|
||||
* the only **required** option with configuration against which you'd like to test.
|
||||
*/
|
||||
exampleConfig: object;
|
||||
/**
|
||||
* optional object of titles for errors and messages.
|
||||
*/
|
||||
title?: Title;
|
||||
/**
|
||||
* optional functions responsible for displaying warning and error messages.
|
||||
*/
|
||||
deprecate?(
|
||||
config: object,
|
||||
key: string,
|
||||
deprecatedConfig: DeprecatedConfig,
|
||||
options: ValidationOptions
|
||||
): boolean;
|
||||
/**
|
||||
* optional functions responsible for displaying warning and error messages.
|
||||
*/
|
||||
error?(
|
||||
key: string,
|
||||
received: any,
|
||||
exampleValue: any,
|
||||
options: ValidationOptions
|
||||
): void;
|
||||
/**
|
||||
* optional functions responsible for displaying warning and error messages.
|
||||
*/
|
||||
unknown?(
|
||||
config: object,
|
||||
exampleConfig: object,
|
||||
key: string,
|
||||
options: ValidationOptions
|
||||
): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
export function validate(
|
||||
config: object,
|
||||
options: ValidationOptions
|
||||
): { hasDeprecationWarnings: boolean; isValid: boolean };
|
||||
13
types/jest-validate/jest-validate-tests.ts
Normal file
13
types/jest-validate/jest-validate-tests.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { validate, format, createDidYouMeanMessage } from 'jest-validate';
|
||||
|
||||
validate(
|
||||
{ a: 0 },
|
||||
{
|
||||
condition: () => false,
|
||||
exampleConfig: { a: 1, b: 2 },
|
||||
},
|
||||
);
|
||||
|
||||
const formatted = format({ c: 3 });
|
||||
|
||||
const didYouMeanMessage = createDidYouMeanMessage('bbb', ['aaa', 'ccc']);
|
||||
22
types/jest-validate/tsconfig.json
Normal file
22
types/jest-validate/tsconfig.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": false,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"jest-validate-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/jest-validate/tslint.json
Normal file
1
types/jest-validate/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user