Skip to content

Instantly share code, notes, and snippets.

@kamiazya
Last active February 26, 2020 08:36
Show Gist options
  • Save kamiazya/17ea59b0461c6e69e12b63a05f2b0331 to your computer and use it in GitHub Desktop.
Save kamiazya/17ea59b0461c6e69e12b63a05f2b0331 to your computer and use it in GitHub Desktop.
// config/jest/add-custom-matchers.ts
import toBeValidDot from '../../test/unit/customMatchers/toBeValidDot';
expect.extend(toBeValidDot);
// test/unit/customMatchers.d.ts
declare namespace jest {
interface Matchers<R, T> {
toBeValidDot(): R;
}
interface Expect {
toBeValidDot: () => any;
}
interface InverseAsymmetricMatchers {
toBeValidDot: () => any;
}
}
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
verbose: true,
collectCoverage: true,
setupFilesAfterEnv: [
'<rootDir>/config/jest/add-custom-matchers.ts',
],
};
// test/unit/customMatchers/toBeValidDot.ts
async function toBeValidDot(this: any, dot: string): Promise<jest.CustomMatcherResult> {
return {
pass: true,
message: () => '',
};
}
export default { toBeValidDot };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment