mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 11:57:33 +08:00
[jest-image-snapshot]: New type definitions.
This commit is contained in:
75
types/jest-image-snapshot/index.d.ts
vendored
Normal file
75
types/jest-image-snapshot/index.d.ts
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
// Type definitions for jest-image-snapshot 2.4
|
||||
// Project: https://github.com/americanexpress/jest-image-snapshot#readme
|
||||
// Definitions by: Janeene Beeforth <https://github.com/dawnmist>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="jest" />
|
||||
|
||||
/**
|
||||
* Options to be passed to the 'pixelmatch' image diffing function.
|
||||
*/
|
||||
export interface PixelmatchOptions {
|
||||
/** Matching threshold, ranges from 0 to 1. Smaller values make the comparison more sensitive. 0.1 by default. */
|
||||
readonly threshold?: number;
|
||||
/** If true, disables detecting and ignoring anti-aliased pixels. false by default. */
|
||||
readonly includeAA?: boolean;
|
||||
}
|
||||
|
||||
export interface MatchImageSnapshotOptions {
|
||||
/**
|
||||
* Custom config passed to 'pixelmatch'
|
||||
*/
|
||||
customDiffConfig?: PixelmatchOptions;
|
||||
/**
|
||||
* Custom snapshots directory.
|
||||
* Absolute path of a directory to keep the snapshot in.
|
||||
*/
|
||||
customSnapshotsDir?: string;
|
||||
/**
|
||||
* A custom name to give this snapshot. If not provided, one is computed automatically.
|
||||
*/
|
||||
customSnapshotIdentifier?: string;
|
||||
/**
|
||||
* Removes coloring from the console output, useful if storing the results to a file.
|
||||
* Defaults to false.
|
||||
*/
|
||||
noColors?: boolean;
|
||||
/**
|
||||
* Sets the threshold that would trigger a test failure based on the failureThresholdType selected. This is different
|
||||
* to the customDiffConfig.threshold above - the customDiffConfig.threshold is the per pixel failure threshold, whereas
|
||||
* this is the failure threshold for the entire comparison.
|
||||
* Defaults to 0.
|
||||
*/
|
||||
failureThreshold?: number;
|
||||
/**
|
||||
* Sets the type of threshold that would trigger a failure.
|
||||
* Defaults to 'pixel'.
|
||||
*/
|
||||
failureThresholdType?: 'pixel' | 'percent';
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to be passed to jest's expect.extend.
|
||||
* Example:
|
||||
* import { toMatchImageSnapshot } from 'jest-image-snapshot';
|
||||
* expect.extend({ toMatchImageSnapshot });
|
||||
*/
|
||||
export function toMatchImageSnapshot(): { message(): string; pass: boolean; };
|
||||
|
||||
/**
|
||||
* Configurable function that can be passed to jest's expect.extend.
|
||||
* Example:
|
||||
* import { configureToMatchImageSnapshot } from 'jest-image-snapshot';
|
||||
* const toMatchImageSnapshot = configureToMatchImageSnapshot({ noColors: true });
|
||||
* expect.extend({ toMatchImageSnapshot });
|
||||
*/
|
||||
export function configureToMatchImageSnapshot(options: MatchImageSnapshotOptions): () => { message(): string; pass: boolean; };
|
||||
|
||||
declare global {
|
||||
namespace jest {
|
||||
interface Matchers<R> {
|
||||
toMatchImageSnapshot(): R;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
types/jest-image-snapshot/jest-image-snapshot-tests.ts
Normal file
23
types/jest-image-snapshot/jest-image-snapshot-tests.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// Typescript Version: 2.3
|
||||
import { toMatchImageSnapshot, configureToMatchImageSnapshot } from 'jest-image-snapshot';
|
||||
|
||||
it('should be able to use toMatchImageSnapshot in a test', () => {
|
||||
expect.extend({ toMatchImageSnapshot });
|
||||
|
||||
expect(400).toMatchImageSnapshot();
|
||||
});
|
||||
|
||||
it('should be able to use configureToMatchImageSnapshot in a test', () => {
|
||||
const matchFn = configureToMatchImageSnapshot({
|
||||
noColors: true,
|
||||
customDiffConfig: {
|
||||
threshold: 5,
|
||||
includeAA: false
|
||||
},
|
||||
failureThreshold: 10,
|
||||
failureThresholdType: 'percent'
|
||||
});
|
||||
expect.extend({ toMatchImageSnapshot: matchFn });
|
||||
|
||||
expect('Me').toMatchImageSnapshot();
|
||||
});
|
||||
23
types/jest-image-snapshot/tsconfig.json
Normal file
23
types/jest-image-snapshot/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"jest-image-snapshot-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/jest-image-snapshot/tslint.json
Normal file
1
types/jest-image-snapshot/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user