From e204ccc77f0a0425bcc1dbca2a3977123cf022d3 Mon Sep 17 00:00:00 2001 From: Janeene Beeforth Date: Sat, 7 Apr 2018 00:16:20 +1000 Subject: [PATCH] [jest-specific-snapshot]: New definition. --- types/jest-specific-snapshot/index.d.ts | 27 +++++++++++++++++++ .../jest-specific-snapshot-tests.ts | 16 +++++++++++ types/jest-specific-snapshot/tsconfig.json | 23 ++++++++++++++++ types/jest-specific-snapshot/tslint.json | 1 + 4 files changed, 67 insertions(+) create mode 100644 types/jest-specific-snapshot/index.d.ts create mode 100644 types/jest-specific-snapshot/jest-specific-snapshot-tests.ts create mode 100644 types/jest-specific-snapshot/tsconfig.json create mode 100644 types/jest-specific-snapshot/tslint.json 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" }