diff --git a/packages/core/src/components/CodeSnippet/CodeSnippet.test.tsx b/packages/core/src/components/CodeSnippet/CodeSnippet.test.tsx
index 466abe6012..7d5d4de087 100644
--- a/packages/core/src/components/CodeSnippet/CodeSnippet.test.tsx
+++ b/packages/core/src/components/CodeSnippet/CodeSnippet.test.tsx
@@ -15,8 +15,9 @@
*/
import React from 'react';
-import { render, fireEvent } from '@testing-library/react';
-import { wrapInTestApp } from '@backstage/test-utils';
+import { fireEvent } from '@testing-library/react';
+import { act } from 'react-dom/test-utils';
+import { renderInTestApp } from '@backstage/test-utils';
import { CodeSnippet } from './CodeSnippet';
@@ -32,24 +33,24 @@ const minProps = {
};
describe('', () => {
- it('renders text without exploding', () => {
- const { getByText } = render(wrapInTestApp());
+ it('renders text without exploding', async () => {
+ const { getByText } = await renderInTestApp();
expect(getByText(/"Hello"/)).toBeInTheDocument();
expect(getByText(/"World"/)).toBeInTheDocument();
});
- it('renders without line numbers', () => {
- const { queryByText } = render(
- wrapInTestApp(),
+ it('renders without line numbers', async () => {
+ const { queryByText } = await renderInTestApp(
+ ,
);
expect(queryByText('1')).not.toBeInTheDocument();
expect(queryByText('2')).not.toBeInTheDocument();
expect(queryByText('3')).not.toBeInTheDocument();
});
- it('renders with line numbers', () => {
- const { getByText } = render(
- wrapInTestApp(),
+ it('renders with line numbers', async () => {
+ const { getByText } = await renderInTestApp(
+ ,
);
expect(getByText('1')).toBeInTheDocument();
expect(getByText('2')).toBeInTheDocument();
@@ -57,12 +58,17 @@ describe('', () => {
});
it('copy code using button', async () => {
+ jest.useFakeTimers();
document.execCommand = jest.fn();
- const { getByTitle } = render(
- wrapInTestApp(),
+ const { getByTitle } = await renderInTestApp(
+ ,
);
const button = getByTitle('Text copied to clipboard');
fireEvent.click(button);
+ act(() => {
+ jest.runAllTimers();
+ });
expect(document.execCommand).toHaveBeenCalled();
+ jest.useRealTimers();
});
});