diff --git a/types/jest-image-snapshot/index.d.ts b/types/jest-image-snapshot/index.d.ts index 007d66f1e9..c516c35a22 100644 --- a/types/jest-image-snapshot/index.d.ts +++ b/types/jest-image-snapshot/index.d.ts @@ -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. */ diff --git a/types/jest-image-snapshot/jest-image-snapshot-tests.ts b/types/jest-image-snapshot/jest-image-snapshot-tests.ts index 07f6debed7..1c8401e07e 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, 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); +});