diff --git a/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx b/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx index 3f95f768677..289731ae01f 100644 --- a/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx +++ b/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx @@ -3,7 +3,7 @@ import { locationService, setDataSourceSrv } from '@grafana/runtime'; import { configureStore } from 'app/store/configureStore'; import { Provider } from 'react-redux'; import { Router } from 'react-router-dom'; -import { render } from '@testing-library/react'; +import { render, act } from '@testing-library/react'; import { PanelAlertTabContent } from './PanelAlertTabContent'; import { DashboardModel, PanelModel } from 'app/features/dashboard/state'; import { @@ -57,13 +57,15 @@ const mocks = { const renderAlertTabContent = (dashboard: DashboardModel, panel: PanelModel) => { const store = configureStore(); - return render( - - - - - - ); + return act(async () => { + render( + + + + + + ); + }); }; const rules = [ diff --git a/public/app/features/alerting/unified/RuleViewer.test.tsx b/public/app/features/alerting/unified/RuleViewer.test.tsx index 69f13c65ff9..5635dc7e47b 100644 --- a/public/app/features/alerting/unified/RuleViewer.test.tsx +++ b/public/app/features/alerting/unified/RuleViewer.test.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { render, screen } from '@testing-library/react'; +import { act, render, screen } from '@testing-library/react'; import { Provider } from 'react-redux'; import { Router } from 'react-router-dom'; import { DataSourceJsonData, PluginMeta } from '@grafana/data'; @@ -29,20 +29,22 @@ jest.mock('@grafana/runtime', () => ({ const store = configureStore(); const renderRuleViewer = () => { - return render( - - - - - - ); + return act(async () => { + render( + + + + + + ); + }); }; describe('RuleViewer', () => { afterEach(() => { jest.resetAllMocks(); }); - it('should render page with grafana alert', () => { + it('should render page with grafana alert', async () => { typeAsJestMock(useCombinedRule).mockReturnValue({ result: mockGrafanaRule as CombinedRule, loading: false, @@ -50,13 +52,13 @@ describe('RuleViewer', () => { requestId: 'A', error: undefined, }); + await renderRuleViewer(); - renderRuleViewer(); expect(screen.getByText('Alerting / View rule')).toBeInTheDocument(); expect(screen.getByText('Test alert')).toBeInTheDocument(); }); - it('should render page with cloud alert', () => { + it('should render page with cloud alert', async () => { typeAsJestMock(useCombinedRule).mockReturnValue({ result: mockCloudRule as CombinedRule, loading: false, @@ -64,7 +66,7 @@ describe('RuleViewer', () => { requestId: 'A', error: undefined, }); - renderRuleViewer(); + await renderRuleViewer(); expect(screen.getByText('Alerting / View rule')).toBeInTheDocument(); expect(screen.getByText('Cloud test alert')).toBeInTheDocument(); }); diff --git a/public/app/features/alerting/unified/utils/redux.ts b/public/app/features/alerting/unified/utils/redux.ts index 39a3d2ed992..9320077dab7 100644 --- a/public/app/features/alerting/unified/utils/redux.ts +++ b/public/app/features/alerting/unified/utils/redux.ts @@ -1,4 +1,3 @@ -import { isArray } from 'angular'; import { AsyncThunk, createSlice, Draft, isAsyncThunkAction, PayloadAction, SerializedError } from '@reduxjs/toolkit'; import { FetchError } from '@grafana/runtime'; import { AppEvents } from '@grafana/data'; @@ -147,7 +146,7 @@ export function messageFromError(e: Error | FetchError | SerializedError): strin msg += `; ${e.data.error}`; } return msg; - } else if (isArray(e.data) && e.data.length && e.data[0]?.message) { + } else if (Array.isArray(e.data) && e.data.length && e.data[0]?.message) { return e.data .map((d) => d?.message) .filter((m) => !!m)