|
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | */ |
7 | 7 |
|
8 | | -import React from 'react'; |
| 8 | +import * as React from 'react'; |
9 | 9 | import SvgComponent, { SvgComponentWithRef } from './SvgComponent'; |
10 | 10 | import ReactDOMClient from 'react-dom/client'; |
11 | 11 |
|
| 12 | +global.IS_REACT_ACT_ENVIRONMENT = true; |
| 13 | + |
12 | 14 | describe('svg component', () => { |
13 | 15 | it('renders without crashing', () => { |
14 | 16 | const div = document.createElement('div'); |
15 | 17 | ReactDOMClient.createRoot(div).render(<SvgComponent />); |
16 | 18 | expect(div.textContent).toBe('logo.svg'); |
17 | 19 | }); |
18 | 20 |
|
19 | | - it('svg root element equals the passed ref', () => { |
| 21 | + it('svg root element equals the passed ref', async () => { |
20 | 22 | const div = document.createElement('div'); |
21 | 23 | 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 | + }); |
25 | 30 | const svgElement = div.getElementsByTagName('svg'); |
26 | 31 | expect(svgElement).toHaveLength(1); |
27 | 32 | expect(svgElement[0]).toBe(someRef.current); |
|
0 commit comments