diff --git a/types/jest-specific-snapshot/index.d.ts b/types/jest-specific-snapshot/index.d.ts new file mode 100644 index 0000000000..ef0e7f4225 --- /dev/null +++ b/types/jest-specific-snapshot/index.d.ts @@ -0,0 +1,27 @@ +// Type definitions for jest-specific-snapshot 0.5 +// Project: https://github.com/igor-dv/jest-specific-snapshot#readme +// Definitions by: Janeene Beeforth +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 + +/// + +declare global { + namespace jest { + interface Matchers { + toMatchSpecificSnapshot(snapshotFilename: string): R; + } + } +} + +/** + * Specify the serializer that should be used by toMatchSpecificSnapshot. + * Note: toMatchSpecificSnapshot ignores the existing jest snapshot serializer settings. If you want to use a custom serializer, + * you need to set it via this addSerializer function. + */ +export function addSerializer(serializer: any): void; + +/** + * This is used to create a customized version of toMatchSpecificSnapshot. + */ +export function toMatchSpecificSnapshot(data: any, snapshotFile: string, testName: string): () => { message(): string; pass: boolean; }; diff --git a/types/jest-specific-snapshot/jest-specific-snapshot-tests.ts b/types/jest-specific-snapshot/jest-specific-snapshot-tests.ts new file mode 100644 index 0000000000..046a563c9e --- /dev/null +++ b/types/jest-specific-snapshot/jest-specific-snapshot-tests.ts @@ -0,0 +1,16 @@ +import { addSerializer, toMatchSpecificSnapshot } from 'jest-specific-snapshot'; +import toJson from 'enzyme-to-json'; + +expect(100).toMatchSpecificSnapshot('mySnapshotFile.snap'); + +addSerializer(toJson); + +function doSomeThing(received: any) { + return received; +} +expect.extend({ + toMatchDecoratedSpecificSnapshot(received, snapshotFile) { + const data = doSomeThing(received); + return toMatchSpecificSnapshot.call(this, data, snapshotFile); + } +}); diff --git a/types/jest-specific-snapshot/tsconfig.json b/types/jest-specific-snapshot/tsconfig.json new file mode 100644 index 0000000000..e4156ae2ff --- /dev/null +++ b/types/jest-specific-snapshot/tsconfig.json @@ -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-specific-snapshot-tests.ts" + ] +} diff --git a/types/jest-specific-snapshot/tslint.json b/types/jest-specific-snapshot/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/jest-specific-snapshot/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }