Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LeanidShutau committed Nov 6, 2018
1 parent dae50e6 commit a64c9de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
29 changes: 14 additions & 15 deletions src/test_utils/public/enzyme_helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@

import { I18nProvider, InjectedIntl, intlShape } from '@kbn/i18n/react';
import { mount, ReactWrapper, render, shallow } from 'enzyme';
import React, { ReactElement } from 'react';
import { IntlProvider } from 'react-intl';
import React, { ReactElement, ValidationMap } from 'react';

// Use fake component to extract `intl` property to use in tests.
const { intl } = (mount(
<I18nProvider>
<br />
</I18nProvider>
).find('IntlProvider') as ReactWrapper<{}, {}, IntlProvider>)
).find('IntlProvider') as ReactWrapper<{}, {}, import('react-intl').IntlProvider>)
.instance()
.getChildContext();

function getOptions(context = {}, childContextTypes = {}, props = {}) {
function getOptions(context = {}, childContextTypes: ValidationMap<any> = {}, props = {}) {
return {
context: {
...context,
Expand All @@ -48,8 +47,8 @@ function getOptions(context = {}, childContextTypes = {}, props = {}) {
/**
* When using React-Intl `injectIntl` on components, props.intl is required.
*/
function nodeWithIntlProp(node: ReactElement<any>): ReactElement<{ intl: InjectedIntl }> {
return React.cloneElement(node, { intl });
function nodeWithIntlProp<T>(node: ReactElement<T>): ReactElement<T & { intl: InjectedIntl }> {
return React.cloneElement<any>(node, { intl });
}

/**
Expand All @@ -59,15 +58,15 @@ function nodeWithIntlProp(node: ReactElement<any>): ReactElement<{ intl: Injecte
* @param options properties to pass into shallow wrapper
* @return The wrapper instance around the rendered output with intl object in context
*/
export function shallowWithIntl(
node: ReactElement<any>,
export function shallowWithIntl<T>(
node: ReactElement<T>,
{
context,
childContextTypes,
...props
}: {
context?: any;
childContextTypes?: any;
childContextTypes?: ValidationMap<any>;
} = {}
) {
const options = getOptions(context, childContextTypes, props);
Expand All @@ -82,15 +81,15 @@ export function shallowWithIntl(
* @param options properties to pass into mount wrapper
* @return The wrapper instance around the rendered output with intl object in context
*/
export function mountWithIntl(
node: ReactElement<any>,
export function mountWithIntl<T>(
node: ReactElement<T>,
{
context,
childContextTypes,
...props
}: {
context?: any;
childContextTypes?: any;
childContextTypes?: ValidationMap<any>;
} = {}
) {
const options = getOptions(context, childContextTypes, props);
Expand All @@ -105,15 +104,15 @@ export function mountWithIntl(
* @param options properties to pass into render wrapper
* @return The wrapper instance around the rendered output with intl object in context
*/
export function renderWithIntl(
node: ReactElement<any>,
export function renderWithIntl<T>(
node: ReactElement<T>,
{
context,
childContextTypes,
...props
}: {
context?: any;
childContextTypes?: any;
childContextTypes?: ValidationMap<any>;
} = {}
) {
const options = getOptions(context, childContextTypes, props);
Expand Down
27 changes: 13 additions & 14 deletions x-pack/test_utils/enzyme_helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@

import { I18nProvider, InjectedIntl, intlShape } from '@kbn/i18n/react';
import { mount, ReactWrapper, render, shallow } from 'enzyme';
import React, { ReactElement } from 'react';
import { IntlProvider } from 'react-intl';
import React, { ReactElement, ValidationMap } from 'react';

// Use fake component to extract `intl` property to use in tests.
const { intl } = (mount(
<I18nProvider>
<br />
</I18nProvider>
).find('IntlProvider') as ReactWrapper<{}, {}, IntlProvider>)
).find('IntlProvider') as ReactWrapper<{}, {}, import('react-intl').IntlProvider>)
.instance()
.getChildContext();

Expand All @@ -42,8 +41,8 @@ function getOptions(context = {}, childContextTypes = {}, props = {}) {
/**
* When using React-Intl `injectIntl` on components, props.intl is required.
*/
function nodeWithIntlProp(node: ReactElement<any>): ReactElement<{ intl: InjectedIntl }> {
return React.cloneElement(node, { intl });
function nodeWithIntlProp<T>(node: ReactElement<T>): ReactElement<T & { intl: InjectedIntl }> {
return React.cloneElement<any>(node, { intl });
}

/**
Expand All @@ -53,15 +52,15 @@ function nodeWithIntlProp(node: ReactElement<any>): ReactElement<{ intl: Injecte
* @param options properties to pass into shallow wrapper
* @return The wrapper instance around the rendered output with intl object in context
*/
export function shallowWithIntl(
node: ReactElement<any>,
export function shallowWithIntl<T>(
node: ReactElement<T>,
{
context,
childContextTypes,
...props
}: {
context?: any;
childContextTypes?: any;
childContextTypes?: ValidationMap<any>;
} = {}
) {
const options = getOptions(context, childContextTypes, props);
Expand All @@ -76,15 +75,15 @@ export function shallowWithIntl(
* @param options properties to pass into mount wrapper
* @return The wrapper instance around the rendered output with intl object in context
*/
export function mountWithIntl(
node: ReactElement<any>,
export function mountWithIntl<T>(
node: ReactElement<T>,
{
context,
childContextTypes,
...props
}: {
context?: any;
childContextTypes?: any;
childContextTypes?: ValidationMap<any>;
} = {}
) {
const options = getOptions(context, childContextTypes, props);
Expand All @@ -99,15 +98,15 @@ export function mountWithIntl(
* @param options properties to pass into render wrapper
* @return The wrapper instance around the rendered output with intl object in context
*/
export function renderWithIntl(
node: ReactElement<any>,
export function renderWithIntl<T>(
node: ReactElement<T>,
{
context,
childContextTypes,
...props
}: {
context?: any;
childContextTypes?: any;
childContextTypes?: ValidationMap<any>;
} = {}
) {
const options = getOptions(context, childContextTypes, props);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"common/**/*",
"server/**/*",
"plugins/**/*",
"test_utils/enzyme_helpers.tsx"
"test_utils/**/*"
],
"exclude": [
"test/**/*"
Expand Down

0 comments on commit a64c9de

Please sign in to comment.