Add typings for chai-jest-snapshot

This commit is contained in:
Matt Perry
2017-08-25 23:24:05 -04:00
parent fa47ad6b0c
commit eb1b9dd426
4 changed files with 109 additions and 0 deletions

View File

@@ -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 = <any> {
currentTest: {
file: 'testfile',
fullTitle: () => 'fullTitle'
}
};
chaiJestSnapshot.setFileName("filename");
chaiJestSnapshot.setTestName("testname");
chaiJestSnapshot.configureUsingMochaContext(mockContext);
chaiJestSnapshot.resetSnapshotRegistry();
chaiJestSnapshot.addSerializer({});

63
types/chai-jest-snapshot/index.d.ts vendored Normal file
View File

@@ -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 <https://github.com/mattvperry>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="chai" />
/// <reference types="mocha" />
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;

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }