diff --git a/types/jest-image-snapshot/index.d.ts b/types/jest-image-snapshot/index.d.ts index 8eeff20990..10d6a2a17d 100644 --- a/types/jest-image-snapshot/index.d.ts +++ b/types/jest-image-snapshot/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for jest-image-snapshot 2.4 +// Type definitions for jest-image-snapshot 2.8 // Project: https://github.com/americanexpress/jest-image-snapshot#readme // Definitions by: Janeene Beeforth // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -26,10 +26,18 @@ export interface MatchImageSnapshotOptions { * Absolute path of a directory to keep the snapshot in. */ customSnapshotsDir?: string; + /** + * A custom absolute path of a directory to keep this diff in + */ + customDiffDir?: string; /** * A custom name to give this snapshot. If not provided, one is computed automatically. */ customSnapshotIdentifier?: string; + /** + * Changes diff image layout direction, default is horizontal. + */ + diffDirection?: 'horizontal' | 'vertical'; /** * Removes coloring from the console output, useful if storing the results to a file. * Defaults to false. @@ -47,6 +55,10 @@ export interface MatchImageSnapshotOptions { * Defaults to 'pixel'. */ failureThresholdType?: 'pixel' | 'percent'; + /** + * Updates a snapshot even if it passed the threshold against the existing one, defaults to false. + */ + updatePassedSnapshot?: boolean; } /** @@ -55,7 +67,7 @@ export interface MatchImageSnapshotOptions { * import { toMatchImageSnapshot } from 'jest-image-snapshot'; * expect.extend({ toMatchImageSnapshot }); */ -export function toMatchImageSnapshot(): { message(): string; pass: boolean; }; +export function toMatchImageSnapshot(options?: MatchImageSnapshotOptions): { message(): string; pass: boolean; }; /** * Configurable function that can be passed to jest's expect.extend. @@ -69,7 +81,7 @@ export function configureToMatchImageSnapshot(options: MatchImageSnapshotOptions declare global { namespace jest { interface Matchers { - toMatchImageSnapshot(): R; + toMatchImageSnapshot(options?: MatchImageSnapshotOptions): R; } } } diff --git a/types/jest-image-snapshot/jest-image-snapshot-tests.ts b/types/jest-image-snapshot/jest-image-snapshot-tests.ts index a2ccb8c777..07f6debed7 100644 --- a/types/jest-image-snapshot/jest-image-snapshot-tests.ts +++ b/types/jest-image-snapshot/jest-image-snapshot-tests.ts @@ -1,5 +1,5 @@ // Typescript Version: 2.3 -import { toMatchImageSnapshot, configureToMatchImageSnapshot } from 'jest-image-snapshot'; +import { toMatchImageSnapshot, configureToMatchImageSnapshot, MatchImageSnapshotOptions } from 'jest-image-snapshot'; it('should be able to use toMatchImageSnapshot in a test', () => { expect.extend({ toMatchImageSnapshot }); @@ -21,3 +21,22 @@ it('should be able to use configureToMatchImageSnapshot in a test', () => { expect('Me').toMatchImageSnapshot(); }); + +it('Should be able to use configuration directly in toMatchImageSnapshot', () => { + expect.extend({ toMatchImageSnapshot }); + + const options: MatchImageSnapshotOptions = { + noColors: true, + customDiffConfig: { + threshold: 5, + includeAA: false + }, + customDiffDir: './diffs', + diffDirection: 'vertical', + updatePassedSnapshot: true, + failureThreshold: 10, + failureThresholdType: 'percent' + }; + + expect('Me').toMatchImageSnapshot(options); +});