From 088cc19a34aeed9fc5a9028fc8c62c0fd7dc7677 Mon Sep 17 00:00:00 2001
From: Angela Chuang <6295984+angorayc@users.noreply.github.com>
Date: Thu, 15 Oct 2020 19:17:20 +0100
Subject: [PATCH] [SecuritySolution] Replace act with waitFor (#80648) (#80702)
* replace act with waitFor
* update unit test
* update unit test
* update unit test
---
.../embeddables/embedded_map.test.tsx | 73 +++++++++----------
.../export_timeline/export_timeline.test.tsx | 31 ++++----
2 files changed, 49 insertions(+), 55 deletions(-)
diff --git a/x-pack/plugins/security_solution/public/network/components/embeddables/embedded_map.test.tsx b/x-pack/plugins/security_solution/public/network/components/embeddables/embedded_map.test.tsx
index 219409b10be6c..f927173b144d6 100644
--- a/x-pack/plugins/security_solution/public/network/components/embeddables/embedded_map.test.tsx
+++ b/x-pack/plugins/security_solution/public/network/components/embeddables/embedded_map.test.tsx
@@ -7,7 +7,7 @@
import { mount, ReactWrapper, shallow } from 'enzyme';
import React from 'react';
import * as redux from 'react-redux';
-import { act } from 'react-dom/test-utils';
+import { waitFor } from '@testing-library/react';
import '../../../common/mock/match_media';
import { useIndexPatterns } from '../../../common/hooks/use_index_patterns';
@@ -107,20 +107,19 @@ describe('EmbeddedMapComponent', () => {
(createEmbeddable as jest.Mock).mockResolvedValue(mockCreateEmbeddable);
- let wrapper: ReactWrapper;
- await act(async () => {
- wrapper = mount(
-
-
-
- );
- });
+ const wrapper: ReactWrapper = mount(
+
+
+
+ );
- wrapper!.update();
+ await waitFor(() => {
+ wrapper.update();
- expect(wrapper!.find('[data-test-subj="EmbeddablePanel"]').exists()).toEqual(true);
- expect(wrapper!.find('[data-test-subj="IndexPatternsMissingPrompt"]').exists()).toEqual(false);
- expect(wrapper!.find('[data-test-subj="loading-panel"]').exists()).toEqual(false);
+ expect(wrapper.find('[data-test-subj="EmbeddablePanel"]').exists()).toEqual(true);
+ expect(wrapper.find('[data-test-subj="IndexPatternsMissingPrompt"]').exists()).toEqual(false);
+ expect(wrapper.find('[data-test-subj="loading-panel"]').exists()).toEqual(false);
+ });
});
test('renders IndexPatternsMissingPrompt', async () => {
@@ -132,20 +131,18 @@ describe('EmbeddedMapComponent', () => {
(createEmbeddable as jest.Mock).mockResolvedValue(mockCreateEmbeddable);
- let wrapper: ReactWrapper;
- await act(async () => {
- wrapper = mount(
-
-
-
- );
- });
-
- wrapper!.update();
+ const wrapper: ReactWrapper = mount(
+
+
+
+ );
+ await waitFor(() => {
+ wrapper.update();
- expect(wrapper!.find('[data-test-subj="EmbeddablePanel"]').exists()).toEqual(false);
- expect(wrapper!.find('[data-test-subj="IndexPatternsMissingPrompt"]').exists()).toEqual(true);
- expect(wrapper!.find('[data-test-subj="loading-panel"]').exists()).toEqual(false);
+ expect(wrapper.find('[data-test-subj="EmbeddablePanel"]').exists()).toEqual(false);
+ expect(wrapper.find('[data-test-subj="IndexPatternsMissingPrompt"]').exists()).toEqual(true);
+ expect(wrapper.find('[data-test-subj="loading-panel"]').exists()).toEqual(false);
+ });
});
test('renders Loader', async () => {
@@ -154,19 +151,17 @@ describe('EmbeddedMapComponent', () => {
(createEmbeddable as jest.Mock).mockResolvedValue(null);
- let wrapper: ReactWrapper;
- await act(async () => {
- wrapper = mount(
-
-
-
- );
- });
-
- wrapper!.update();
+ const wrapper: ReactWrapper = mount(
+
+
+
+ );
+ await waitFor(() => {
+ wrapper.update();
- expect(wrapper!.find('[data-test-subj="EmbeddablePanel"]').exists()).toEqual(false);
- expect(wrapper!.find('[data-test-subj="IndexPatternsMissingPrompt"]').exists()).toEqual(false);
- expect(wrapper!.find('[data-test-subj="loading-panel"]').exists()).toEqual(true);
+ expect(wrapper.find('[data-test-subj="EmbeddablePanel"]').exists()).toEqual(false);
+ expect(wrapper.find('[data-test-subj="IndexPatternsMissingPrompt"]').exists()).toEqual(false);
+ expect(wrapper.find('[data-test-subj="loading-panel"]').exists()).toEqual(true);
+ });
});
});
diff --git a/x-pack/plugins/security_solution/public/timelines/components/open_timeline/export_timeline/export_timeline.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/open_timeline/export_timeline/export_timeline.test.tsx
index d0cfbaccde7dd..31051a51a58d5 100644
--- a/x-pack/plugins/security_solution/public/timelines/components/open_timeline/export_timeline/export_timeline.test.tsx
+++ b/x-pack/plugins/security_solution/public/timelines/components/open_timeline/export_timeline/export_timeline.test.tsx
@@ -12,7 +12,7 @@ import { mockSelectedTimeline } from './mocks';
import * as i18n from '../translations';
import { ReactWrapper, mount } from 'enzyme';
-import { act } from 'react-dom/test-utils';
+import { waitFor } from '@testing-library/react';
import { useParams } from 'react-router-dom';
jest.mock('../translations', () => {
@@ -102,15 +102,14 @@ describe('TimelineDownloader', () => {
...defaultTestProps,
};
- await act(() => {
- wrapper = mount();
- });
-
- wrapper.update();
+ wrapper = mount();
+ await waitFor(() => {
+ wrapper.update();
- expect(mockDispatchToaster.mock.calls[0][0].title).toEqual(
- i18n.SUCCESSFULLY_EXPORTED_TIMELINES
- );
+ expect(mockDispatchToaster.mock.calls[0][0].title).toEqual(
+ i18n.SUCCESSFULLY_EXPORTED_TIMELINES
+ );
+ });
});
test('With correct toast message on success for exported templates', async () => {
@@ -119,15 +118,15 @@ describe('TimelineDownloader', () => {
};
(useParams as jest.Mock).mockReturnValue({ tabName: 'template' });
- await act(() => {
- wrapper = mount();
- });
+ wrapper = mount();
- wrapper.update();
+ await waitFor(() => {
+ wrapper.update();
- expect(mockDispatchToaster.mock.calls[0][0].title).toEqual(
- i18n.SUCCESSFULLY_EXPORTED_TIMELINES
- );
+ expect(mockDispatchToaster.mock.calls[0][0].title).toEqual(
+ i18n.SUCCESSFULLY_EXPORTED_TIMELINES
+ );
+ });
});
});
});