Skip to content

Commit

Permalink
wow, seems all good? nice
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Sep 29, 2020
1 parent 91cbafc commit 5f23b0d
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/dev/jest/setup/react_testing_library.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import '@testing-library/jest-dom';
/**
* PLEASE NOTE:
* Importing '@testing-library/react' registers an `afterEach(cleanup)` side effect.
* It has tricky code that flushes pending promises, that could lead to unpredictable test failures
* It has tricky code that flushes pending promises, that previously led to unpredictable test failures
* https://github.com/elastic/kibana/issues/59469
* But since newer versions it has stabilised itself
*/
import { configure } from '@testing-library/react';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import React from 'react';
import { wait } from '@testing-library/dom';
import { cleanup, render } from '@testing-library/react/pure';
import { render } from '@testing-library/react';
import {
HelloWorldEmbeddable,
HelloWorldEmbeddableFactoryDefinition,
Expand All @@ -29,8 +29,6 @@ import { EmbeddableRenderer } from './embeddable_renderer';
import { embeddablePluginMock } from '../../mocks';

describe('<EmbeddableRenderer/>', () => {
afterEach(cleanup);

test('Render embeddable', () => {
const embeddable = new HelloWorldEmbeddable({ id: 'hello' });
const { getByTestId } = render(<EmbeddableRenderer embeddable={embeddable} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
* under the License.
*/
import React from 'react';
import { wait } from '@testing-library/dom';
import { cleanup, render } from '@testing-library/react/pure';
import { wait, render } from '@testing-library/react';
import { ErrorEmbeddable } from './error_embeddable';
import { EmbeddableRoot } from './embeddable_root';

afterEach(cleanup);

test('ErrorEmbeddable renders an embeddable', async () => {
const embeddable = new ErrorEmbeddable('some error occurred', { id: '123', title: 'Error' });
const { getByTestId, getByText } = render(<EmbeddableRoot embeddable={embeddable} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
*/

import React from 'react';
import { wait } from '@testing-library/dom';
import { render, cleanup } from '@testing-library/react/pure';
import { wait, render } from '@testing-library/react';
import MarkdownVisComponent from './markdown_vis_controller';

afterEach(cleanup);

describe('markdown vis controller', () => {
it('should set html from markdown params', async () => {
const vis = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
*/

import React from 'react';
import { render, cleanup, act } from '@testing-library/react/pure';
import { render, act } from '@testing-library/react';
import { MenuItem } from './menu_item';
import { createStateContainer } from '../../../../../../../../src/plugins/kibana_utils/public';
import { UiActionsEnhancedDynamicActionManager as DynamicActionManager } from '../../../../../../ui_actions_enhanced/public';
import { EnhancedEmbeddable } from '../../../../../../embeddable_enhanced/public';

afterEach(cleanup);

test('<MenuItem/>', () => {
const state = createStateContainer<{ events: object[] }>({ events: [] });
const { getByText, queryByText } = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React from 'react';
import { cleanup, fireEvent, render } from '@testing-library/react/pure';
import { fireEvent, render } from '@testing-library/react';
import { TEST_SUBJ_ACTION_FACTORY_ITEM, TEST_SUBJ_SELECTED_ACTION_FACTORY } from './action_wizard';
import {
dashboardFactory,
Expand All @@ -17,10 +17,6 @@ import {
import { ActionFactory } from '../../dynamic_actions';
import { licensingMock } from '../../../../licensing/public/mocks';

// TODO: afterEach is not available for it globally during setup
// https://github.com/elastic/kibana/issues/59469
afterEach(cleanup);

test('Pick and configure action', () => {
const screen = render(<Demo actionFactories={[dashboardFactory, urlFactory]} />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React from 'react';
import { cleanup, fireEvent, render, wait } from '@testing-library/react/pure';
import { fireEvent, render, wait } from '@testing-library/react';
import { createFlyoutManageDrilldowns } from './connected_flyout_manage_drilldowns';
import {
mockGetTriggerInfo,
Expand All @@ -30,9 +30,6 @@ const FlyoutManageDrilldowns = createFlyoutManageDrilldowns({
getTrigger: mockGetTriggerInfo,
});

// https://github.com/elastic/kibana/issues/59469
afterEach(cleanup);

beforeEach(() => {
storage.clear();
mockDynamicActionManager.state.set({ ...mockDynamicActionManager.state.get(), events: [] });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

import React from 'react';
import { render } from 'react-dom';
import { render as renderTestingLibrary, fireEvent, cleanup } from '@testing-library/react/pure';
import { render as renderTestingLibrary, fireEvent } from '@testing-library/react';
import { FlyoutFrame } from './index';

afterEach(cleanup);

describe('<FlyoutFrame>', () => {
test('renders without crashing', () => {
const div = document.createElement('div');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import React from 'react';
import { render } from 'react-dom';
import { FormDrilldownWizard } from './form_drilldown_wizard';
import { render as renderTestingLibrary, fireEvent, cleanup } from '@testing-library/react/pure';
import { render as renderTestingLibrary, fireEvent } from '@testing-library/react';
import { txtNameOfDrilldown } from './i18n';
import { Trigger, TriggerId } from '../../../../../../../src/plugins/ui_actions/public';

afterEach(cleanup);

const otherProps = {
actionFactoryContext: { triggers: [] as TriggerId[] },
supportedTriggers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
*/

import React from 'react';
import { cleanup, fireEvent, render } from '@testing-library/react/pure';
import { fireEvent, render } from '@testing-library/react';
import {
DrilldownListItem,
ListManageDrilldowns,
TEST_SUBJ_DRILLDOWN_ITEM,
} from './list_manage_drilldowns';

// TODO: for some reason global cleanup from RTL doesn't work
// afterEach is not available for it globally during setup
afterEach(cleanup);

const drilldowns: DrilldownListItem[] = [
{ id: '1', actionName: 'Dashboard', drilldownName: 'Drilldown 1' },
{ id: '2', actionName: 'Dashboard', drilldownName: 'Drilldown 2' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
*/

import { Demo } from './test_samples/demo';
import { cleanup, fireEvent, render } from '@testing-library/react/pure';
import { fireEvent, render } from '@testing-library/react';
import React from 'react';

afterEach(cleanup);

test('configure valid URL template', () => {
const screen = render(<Demo />);

Expand Down

0 comments on commit 5f23b0d

Please sign in to comment.