From 741d1d78c61854322184244d08aff3b530064b56 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Fri, 9 Sep 2022 18:39:00 -0300 Subject: [PATCH] test: Fixes act errors in ReportModal test (#21420) --- .../ReportModal/ReportModal.test.tsx | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/superset-frontend/src/components/ReportModal/ReportModal.test.tsx b/superset-frontend/src/components/ReportModal/ReportModal.test.tsx index 1db3aa0fd6..d33d7d62e1 100644 --- a/superset-frontend/src/components/ReportModal/ReportModal.test.tsx +++ b/superset-frontend/src/components/ReportModal/ReportModal.test.tsx @@ -20,7 +20,7 @@ import * as React from 'react'; import userEvent from '@testing-library/user-event'; import sinon from 'sinon'; import fetchMock from 'fetch-mock'; -import { render, screen } from 'spec/helpers/testing-library'; +import { render, screen, waitFor } from 'spec/helpers/testing-library'; import * as featureFlags from 'src/featureFlags'; import * as actions from 'src/reports/actions/reports'; import { FeatureFlag } from '@superset-ui/core'; @@ -33,6 +33,8 @@ fetchMock.get(REPORT_ENDPOINT, {}); const NOOP = () => {}; +jest.mock('src/components/Icons/Icon', () => () => ); + const defaultProps = { addDangerToast: NOOP, addSuccessToast: NOOP, @@ -156,7 +158,7 @@ describe('Email Report Modal', () => { // Click "Add" button to create a new email report const addButton = screen.getByRole('button', { name: /add/i }); - userEvent.click(addButton); + await waitFor(() => userEvent.click(addButton)); // Mock addReport from Redux const makeRequest = () => { @@ -164,16 +166,15 @@ describe('Email Report Modal', () => { return request(dispatch); }; - return makeRequest().then(() => { - // 🐞 ----- There are 2 POST calls at this point ----- 🐞 + await makeRequest(); - // addReport's mocked POST return should match the mocked values - expect(fetchMock.lastOptions()?.body).toEqual(stringyReportValues); - // Dispatch should be called once for addReport - expect(dispatch.callCount).toBe(2); - const reportCalls = fetchMock.calls(REPORT_ENDPOINT); - expect(reportCalls).toHaveLength(2); - }); + // 🐞 ----- There are 2 POST calls at this point ----- 🐞 + + // addReport's mocked POST return should match the mocked values + expect(fetchMock.lastOptions()?.body).toEqual(stringyReportValues); + expect(dispatch.callCount).toBe(2); + const reportCalls = fetchMock.calls(REPORT_ENDPOINT); + expect(reportCalls).toHaveLength(2); }); }); });