Skip to content

Commit

Permalink
fix: fix TypeScript definitions (#7)
Browse files Browse the repository at this point in the history
See #2 (comment) for context.

I found a couple of issues in the previous TypeScript definitions:
- There was no declaration of `toMatchFile`, so it couldn't be imported (e.g. `import { toMatchFile } from "jest-file-snapshot";`)
- The augmentation of the expect() function exposed by Jest required wrapping the namespace into `declare global { ... }`
  • Loading branch information
fwouts authored and satya164 committed Mar 20, 2019
1 parent 9265ba9 commit 0a89b88
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@

import { DiffOptions } from 'jest-diff';

declare type FileMatcherOptions = {
diff: DiffOptions
declare module 'jest-file-snapshot' {
export const toMatchFile: jest.CustomMatcher;
}

declare namespace jest {
interface Matchers<R> {
toMatchFile: (output: string, filename?: string, options?: FileMatcherOptions) => void
}
declare interface FileMatcherOptions {
diff: DiffOptions;
}

declare global {
namespace jest {
interface Matchers<R> {
toMatchFile: (
output: string,
filename?: string,
options?: FileMatcherOptions
) => void;
}

interface Expect {
toMatchFile: (output: string, filename?: string, options?: FileMatcherOptions) => void
interface Expect {
toMatchFile: (
output: string,
filename?: string,
options?: FileMatcherOptions
) => void;
}
}
}

0 comments on commit 0a89b88

Please sign in to comment.