From d83339fdaa332d1c22663f20e997d7baecec9c1a Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Tue, 9 Jul 2019 16:27:00 -0700 Subject: [PATCH] [@types/enzyme] Add missing Wrapper debug options parameter (#36604) * [@types/enzyme] add missing wrapper debug options * [@types/enzyme] add wrapper debug tests * lint * add name to definitions * chore: format comments to be intellisense-friendly * chore: remove newline --- types/enzyme/enzyme-tests.tsx | 6 ++++++ types/enzyme/index.d.ts | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/types/enzyme/enzyme-tests.tsx b/types/enzyme/enzyme-tests.tsx index a576908ef3..a6e18b3af8 100644 --- a/types/enzyme/enzyme-tests.tsx +++ b/types/enzyme/enzyme-tests.tsx @@ -456,6 +456,9 @@ function ShallowWrapperTest() { function test_debug() { stringVal = shallowWrapper.debug(); + stringVal = shallowWrapper.debug({ verbose: false }); + stringVal = shallowWrapper.debug({ ignoreProps: true }); + stringVal = shallowWrapper.debug({ ignoreProps: true, verbose: true }); } function test_type() { @@ -885,6 +888,9 @@ function ReactWrapperTest() { function test_debug() { stringVal = reactWrapper.debug(); + stringVal = reactWrapper.debug({ verbose: false }); + stringVal = reactWrapper.debug({ ignoreProps: true }); + stringVal = reactWrapper.debug({ ignoreProps: true, verbose: true }); } function test_type() { diff --git a/types/enzyme/index.d.ts b/types/enzyme/index.d.ts index 66c353b5be..8aaa5235f6 100644 --- a/types/enzyme/index.d.ts +++ b/types/enzyme/index.d.ts @@ -11,6 +11,7 @@ // Christian Rackerseder // Mateusz SokoĊ‚a // Braiden Cutforth +// Erick Zhao // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.1 @@ -102,9 +103,15 @@ export interface CommonWrapper

> { * @param ...args The argments to the invokePropName function * @returns The value of the function. */ - invoke void) | undefined ? K : never - }[keyof P]>>(invokePropName: K): P[K]; + invoke< + K extends NonNullable< + { + [K in keyof P]: P[K] extends ((...arg: any[]) => void) | undefined ? K : never; + }[keyof P] + > + >( + invokePropName: K + ): P[K]; /** * Returns whether or not the current node matches a provided selector. @@ -300,7 +307,12 @@ export interface CommonWrapper

> { * Returns an html-like string of the wrapper for debugging purposes. Useful to print out to the console when * tests are not passing when you expect them to. */ - debug(): string; + debug(options?: { + /** Whether props should be omitted in the resulting string. Props are included by default. */ + ignoreProps?: boolean; + /** Whether arrays and objects passed as props should be verbosely printed. */ + verbose?: boolean; + }): string; /** * Returns the name of the current node of the wrapper.