[jest-image-snapshot]: Update to fix #32760.

* Add new options to MatchImageSnapshotOptions
* toMatchImageSnapshot can be given options directly instead of needing
   to use configureToMatchImageSnapshot for specifying the options.
This commit is contained in:
Janeene Beeforth
2019-02-05 10:38:19 +11:00
parent 678a6b1912
commit 5b327cf997
2 changed files with 35 additions and 4 deletions

View File

@@ -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 <https://github.com/dawnmist>
// 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<R> {
toMatchImageSnapshot(): R;
toMatchImageSnapshot(options?: MatchImageSnapshotOptions): R;
}
}
}

View File

@@ -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);
});