diff --git a/enzyme/enzyme-tests.tsx b/enzyme/enzyme-tests.tsx index 037803024b..efec976d01 100644 --- a/enzyme/enzyme-tests.tsx +++ b/enzyme/enzyme-tests.tsx @@ -44,6 +44,15 @@ namespace ShallowWrapperTest { stringVal: String, elementWrapper: ShallowWrapper + function test_shallow_options() { + shallow(, { + context: { + test: "a", + lifecycleExperimental: true + } + }); + } + function test_find() { elementWrapper = shallowWrapper.find('.selector'); shallowWrapper = shallowWrapper.find(MyComponent); @@ -281,6 +290,10 @@ namespace ShallowWrapperTest { function test_everyWhere() { boolVal = shallowWrapper.everyWhere((aShallowWrapper: ShallowWrapper) => true); } + + function test_isEmptyRender() { + boolVal = shallowWrapper.isEmptyRender(); + } } @@ -301,6 +314,13 @@ namespace ReactWrapperTest { function test_mount() { reactWrapper = reactWrapper.mount(); + + mount(, { + attachTo: document.getElementById('test'), + context: { + a: "b" + } + }); } function test_ref() { @@ -542,6 +562,9 @@ namespace ReactWrapperTest { function test_everyWhere() { boolVal = reactWrapper.everyWhere((aReactWrapper: ReactWrapper) => true); } + function test_isEmptyRender() { + boolVal = reactWrapper.isEmptyRender(); + } } // CheerioWrapper diff --git a/enzyme/enzyme.d.ts b/enzyme/enzyme.d.ts index dbc2b4a76c..4a5bf2beac 100644 --- a/enzyme/enzyme.d.ts +++ b/enzyme/enzyme.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Enzyme v2.3.0 +// Type definitions for Enzyme v2.4.1 // Project: https://github.com/airbnb/enzyme // Definitions by: Marian Palkus , Cap3 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -448,6 +448,11 @@ declare module "enzyme" { * Returns a wrapper with the direct parent of the node in the current wrapper. */ parent(): ShallowWrapper; + + /** + * Returns true if renderer returned null + */ + isEmptyRender(): boolean; } export interface ReactWrapper extends CommonWrapper { @@ -544,26 +549,57 @@ declare module "enzyme" { * Returns a wrapper with the direct parent of the node in the current wrapper. */ parent(): ReactWrapper; + + /** + * Returns true if renderer returned null + */ + isEmptyRender(): boolean; } export interface CheerioWrapper extends CommonWrapper { } + export interface ShallowRendererProps { + /** + * Enable experimental support for full react lifecycle methods + */ + lifecycleExperimental?: boolean; + /** + * Context to be passed into the component + */ + context?: {}; + } + + export interface MountRendererProps { + /** + * Context to be passed into the component + */ + context?: {}; + /** + * DOM Element to attach the component to + */ + attachTo?: HTMLElement; + /** + * Merged contextTypes for all children of the wrapper + */ + childContextTypes?: {}; + } + /** * Shallow rendering is useful to constrain yourself to testing a component as a unit, and to ensure that * your tests aren't indirectly asserting on behavior of child components. * @param node * @param [options] */ - export function shallow(node: ReactElement

, options?: any): ShallowWrapper; + export function shallow(node: ReactElement

, options?: ShallowRendererProps): ShallowWrapper; /** * Mounts and renders a react component into the document and provides a testing wrapper around it. * @param node * @param [options] */ - export function mount(node: ReactElement

, options?: any): ReactWrapper; + export function mount(node: ReactElement

, options?: MountRendererProps): ReactWrapper; /** * Render react components to static HTML and analyze the resulting HTML structure.