diff --git a/types/chai-jest-snapshot/chai-jest-snapshot-tests.ts b/types/chai-jest-snapshot/chai-jest-snapshot-tests.ts new file mode 100644 index 0000000000..05cf190765 --- /dev/null +++ b/types/chai-jest-snapshot/chai-jest-snapshot-tests.ts @@ -0,0 +1,23 @@ +import chaiJestSnapshot from 'chai-jest-snapshot'; +import { expect } from 'chai'; + +chai.use(chaiJestSnapshot); + +expect({}).to.matchSnapshot(); +expect({}).to.matchSnapshot(true); +expect({}).to.matchSnapshot("filename"); +expect({}).to.matchSnapshot("filename", "snapshotname"); +expect({}).to.matchSnapshot("filename", "snapshotname", false); + +const mockContext: Mocha.IBeforeAndAfterContext = { + currentTest: { + file: 'testfile', + fullTitle: () => 'fullTitle' + } +}; + +chaiJestSnapshot.setFileName("filename"); +chaiJestSnapshot.setTestName("testname"); +chaiJestSnapshot.configureUsingMochaContext(mockContext); +chaiJestSnapshot.resetSnapshotRegistry(); +chaiJestSnapshot.addSerializer({}); diff --git a/types/chai-jest-snapshot/index.d.ts b/types/chai-jest-snapshot/index.d.ts new file mode 100644 index 0000000000..f19158e282 --- /dev/null +++ b/types/chai-jest-snapshot/index.d.ts @@ -0,0 +1,63 @@ +// Type definitions for chai-jest-snapshot 1.3 +// Project: https://github.com/suchipi/chai-jest-snapshot#readme +// Definitions by: Matt Perry +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// + +declare global { + namespace Chai { + interface Assertion { + /** + * Assert that the object matches the snapshot + * @param snapshotFilename + * @param snapshotName + * @param update + */ + matchSnapshot(snapshotFilename?: string, snapshotName?: string, update?: boolean): Assertion; + matchSnapshot(update: boolean): Assertion; + } + } +} + +interface ChaiJestSnapshot { + /** + * Chai bootstrapper + * @param chai + * @param utils + */ + (chai: any, utils: any): void; + + /** + * Set snapshot file name + * @param filename + */ + setFileName(filename: string): void; + + /** + * Set snapshot test name + * @param testname + */ + setTestName(testname: string): void; + + /** + * Configure snapshot name using mocha context + * @param context + */ + configureUsingMochaContext(context: Mocha.IBeforeAndAfterContext): void; + + /** + * Reset snapshot registry + */ + resetSnapshotRegistry(): void; + + /** + * Add a serializer plugin + * @param serializer + */ + addSerializer(serializer: any): void; +} + +declare var ChaiJestSnapshot: ChaiJestSnapshot; +export default ChaiJestSnapshot; diff --git a/types/chai-jest-snapshot/tsconfig.json b/types/chai-jest-snapshot/tsconfig.json new file mode 100644 index 0000000000..32dea54632 --- /dev/null +++ b/types/chai-jest-snapshot/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "chai-jest-snapshot-tests.ts" + ] +} diff --git a/types/chai-jest-snapshot/tslint.json b/types/chai-jest-snapshot/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/chai-jest-snapshot/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }