diff --git a/types/wordpress__jest-console/index.d.ts b/types/wordpress__jest-console/index.d.ts new file mode 100644 index 0000000000..ecda81d6f7 --- /dev/null +++ b/types/wordpress__jest-console/index.d.ts @@ -0,0 +1,51 @@ +// Type definitions for @wordpress/jest-console 3.0 +// Project: https://github.com/wordpress/gutenberg/tree/master/packages/jest-console/readme.md +// Definitions by: Damien Sorel +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +/// + +declare namespace jest { + interface Matchers { + /** + * Ensure that `console.error` function was called. + */ + toHaveErrored(): R; + + /** + * Ensure that `console.error` function was called with specific arguments. + */ + toHaveErroredWith(...args: any[]): R; + + /** + * Ensure that `console.info` function was called. + */ + toHaveInformed(): R; + + /** + * Ensure that `console.info` function was called with specific arguments. + */ + toHaveInformedWith(...args: any[]): R; + + /** + * Ensure that `console.log` function was called. + */ + toHaveLogged(): R; + + /** + * Ensure that `console.log` function was called with specific arguments. + */ + toHaveLoggedWith(...args: any[]): R; + + /** + * Ensure that `console.warn` function was called. + */ + toHaveWarned(): R; + + /** + * Ensure that `console.warn` function was called with specific arguments. + */ + toHaveWarnedWith(...args: any[]): R; + } +} diff --git a/types/wordpress__jest-console/jest-console-tests.ts b/types/wordpress__jest-console/jest-console-tests.ts new file mode 100644 index 0000000000..7c8eec6968 --- /dev/null +++ b/types/wordpress__jest-console/jest-console-tests.ts @@ -0,0 +1,13 @@ +it('uses the console', () => { + expect(console).toHaveErrored(); + expect(console).toHaveErroredWith('message'); + + expect(console).toHaveInformed(); + expect(console).toHaveInformedWith('message'); + + expect(console).toHaveLogged(); + expect(console).toHaveLoggedWith('message'); + + expect(console).toHaveWarned(); + expect(console).toHaveWarnedWith('message'); +}); diff --git a/types/wordpress__jest-console/tsconfig.json b/types/wordpress__jest-console/tsconfig.json new file mode 100644 index 0000000000..f21c4b6ce7 --- /dev/null +++ b/types/wordpress__jest-console/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jest-console-tests.ts" + ] +} diff --git a/types/wordpress__jest-console/tslint.json b/types/wordpress__jest-console/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/wordpress__jest-console/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }