Skip to content

Commit 96f98e9

Browse files
committed
Add act
1 parent 9bd1974 commit 96f98e9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/react-scripts/fixtures/kitchensink/template/src/features/webpack/SvgComponent.test.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import React from 'react';
8+
import * as React from 'react';
99
import SvgComponent, { SvgComponentWithRef } from './SvgComponent';
1010
import ReactDOMClient from 'react-dom/client';
1111

12+
global.IS_REACT_ACT_ENVIRONMENT = true;
13+
1214
describe('svg component', () => {
1315
it('renders without crashing', () => {
1416
const div = document.createElement('div');
1517
ReactDOMClient.createRoot(div).render(<SvgComponent />);
1618
expect(div.textContent).toBe('logo.svg');
1719
});
1820

19-
it('svg root element equals the passed ref', () => {
21+
it('svg root element equals the passed ref', async () => {
2022
const div = document.createElement('div');
2123
const someRef = React.createRef();
22-
ReactDOMClient.createRoot(div).render(
23-
<SvgComponentWithRef ref={someRef} />
24-
);
24+
// eslint-disable-next-line testing-library/no-unnecessary-act
25+
await React.act(async () => {
26+
ReactDOMClient.createRoot(div).render(
27+
<SvgComponentWithRef ref={someRef} />
28+
);
29+
});
2530
const svgElement = div.getElementsByTagName('svg');
2631
expect(svgElement).toHaveLength(1);
2732
expect(svgElement[0]).toBe(someRef.current);

0 commit comments

Comments
 (0)