diff --git a/public/app/plugins/datasource/loki/components/LokiQueryField.test.tsx b/public/app/plugins/datasource/loki/components/LokiQueryField.test.tsx index 0e46eb28a9f..5c304700ffb 100644 --- a/public/app/plugins/datasource/loki/components/LokiQueryField.test.tsx +++ b/public/app/plugins/datasource/loki/components/LokiQueryField.test.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react'; +import { render, screen, waitFor } from '@testing-library/react'; import React, { ComponentProps } from 'react'; import { dateTime } from '@grafana/data'; @@ -33,7 +33,9 @@ describe('LokiQueryField', () => { it('refreshes metrics when time range changes over 1 minute', async () => { const { rerender } = render(); - expect(await screen.findByText('Loading...')).toBeInTheDocument(); + await waitFor(async () => { + expect(await screen.findByText('Loading...')).toBeInTheDocument(); + }); expect(props.datasource.languageProvider.fetchLabels).not.toHaveBeenCalled(); @@ -55,7 +57,9 @@ describe('LokiQueryField', () => { it('does not refreshes metrics when time range change by less than 1 minute', async () => { const { rerender } = render(); - expect(await screen.findByText('Loading...')).toBeInTheDocument(); + await waitFor(async () => { + expect(await screen.findByText('Loading...')).toBeInTheDocument(); + }); expect(props.datasource.languageProvider.fetchLabels).not.toHaveBeenCalled(); diff --git a/public/app/plugins/datasource/loki/components/monaco-query-field/MonacoFieldWrapper.test.tsx b/public/app/plugins/datasource/loki/components/monaco-query-field/MonacoFieldWrapper.test.tsx index 15c25be1d6c..7ff5671f8cd 100644 --- a/public/app/plugins/datasource/loki/components/monaco-query-field/MonacoFieldWrapper.test.tsx +++ b/public/app/plugins/datasource/loki/components/monaco-query-field/MonacoFieldWrapper.test.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react'; +import { render, screen, waitFor } from '@testing-library/react'; import React from 'react'; import { createLokiDatasource } from '../../__mocks__/datasource'; @@ -24,6 +24,8 @@ describe('MonacoFieldWrapper', () => { test('Renders with no errors', async () => { renderComponent(); - expect(await screen.findByText('Loading...')).toBeInTheDocument(); + await waitFor(async () => { + expect(await screen.findByText('Loading...')).toBeInTheDocument(); + }); }); });