[jest-image-snapshot] Fix string not assignable to customSnapshotIdentifier fields in MatchImageSnapshotOptions (#41118)

This commit is contained in:
Nubami SQReder 2019-12-23 18:48:30 +03:00 committed by Andrew Branch
parent 57bd61b26b
commit a2fb19e08d
2 changed files with 25 additions and 7 deletions

View File

@ -36,12 +36,14 @@ export interface MatchImageSnapshotOptions {
* it is called with an object containing testPath, currentTestName, counter and defaultIdentifier as its first
* argument. The function must return an identifier to use for the snapshot.
*/
customSnapshotIdentifier?: (parameters: {
testPath: string;
currentTestName: string;
counter: number;
defaultIdentifier: string;
}) => string | string;
customSnapshotIdentifier?:
| ((parameters: {
testPath: string;
currentTestName: string;
counter: number;
defaultIdentifier: string;
}) => string)
| string;
/**
* Changes diff image layout direction, default is horizontal.
*/

View File

@ -1,5 +1,5 @@
// Typescript Version: 2.3
import { toMatchImageSnapshot, configureToMatchImageSnapshot, MatchImageSnapshotOptions } from 'jest-image-snapshot';
import { configureToMatchImageSnapshot, MatchImageSnapshotOptions, toMatchImageSnapshot } from 'jest-image-snapshot';
it('should be able to use toMatchImageSnapshot in a test', () => {
expect.extend({ toMatchImageSnapshot });
@ -40,3 +40,19 @@ it('Should be able to use configuration directly in toMatchImageSnapshot', () =>
expect('Me').toMatchImageSnapshot(options);
});
it('Should be able to use string as customSnapshotIdentifier', () => {
const options: MatchImageSnapshotOptions = {
customSnapshotIdentifier: 'string identifier',
};
expect('Me').toMatchImageSnapshot(options);
});
it('Should be able to use callback as customSnapshotIdentifier', () => {
const options: MatchImageSnapshotOptions = {
customSnapshotIdentifier: () => 'string identifier',
};
expect('Me').toMatchImageSnapshot(options);
});