# Testing render shows deprecation warning

**URL:** <https://community.apollographql.com/t/testing-render-shows-deprecation-warning/8107>\
**Category:** Client SDKs\
**Tags:** client\
**Created:** [January 16, 2025, 10:16pm UTC](https://community.apollographql.com/t/testing-render-shows-deprecation-warning/8107 "2025-01-16T22:16:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephan-buckmaster](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/stephan-buckmaster/32/5460_2.png) [@stephan-buckmaster](https://community.apollographql.com/u/stephan-buckmaster)\
**Post date:** [January 16, 2025, 10:16pm UTC](https://community.apollographql.com/t/testing-render-shows-deprecation-warning/8107/1 "2025-01-16T22:16:08Z")

</div>

I followed the tutorial for testing React components at

> **[Testing React components](https://www.apollographql.com/docs/react/development-testing/testing)**
>
> Using MockedProvider and associated APIs

I get a deprecation warning which I tried to address following the instructions given, but they persist.

Here is part of the test code

> import { React, act } from ‘react’  
> import ‘@testing-library/jest-dom’  
> import { render, screen } from ‘@testing-library/react’;  
> import { MockedProvider } from “@apollo/react-testing”;
> 
> mock = {…}  
> test(‘renders air quality data correctly’, async () =\> {  
> render(  
>   
>   
>   
> );

The logs show

> ```
> console.error
> Warning: `ReactDOMTestUtils.act` is deprecated in favor of `React.act`. Import `act` from `react` instead of `react-dom/test-utils`. See https://react.dev/warnings/react-dom-test-utils for more info.
> 
> 33 |
> 34 | test('renders air quality data correctly', async () => {
> > 35 | render(
> | ^
> 36 | <MockedProvider mocks={[mock]} addTypename={false}>
> 37 | <LatestAirVisualDeviceMeasurement />
> 38 | </MockedProvider>
> 
> at printWarning (node_modules/react-dom/cjs/react-dom-test-utils.development.js:71:30)
> at error (node_modules/react-dom/cjs/react-dom-test-utils.development.js:45:7)
> at actWithWarning (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1736:7)
> 
> ```

I am importing as is explained in the warning:

import { React, act } from ‘react’

What can I look at changing?

---

<div class="post-metadata">

**Author:** ![jerelmiller](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jerelmiller/32/3314_2.png) [@jerelmiller](https://community.apollographql.com/u/jerelmiller)\
**Post date:** [January 16, 2025, 10:20pm UTC](https://community.apollographql.com/t/testing-render-shows-deprecation-warning/8107/2 "2025-01-16T22:20:19Z")

</div>

Hey @stephan-buckmaster 👋

Seems we have a docs page that hasn’t been updated in a while. What version of React are you using? I know React has moved that import around a bit.

That said, it looks like you’re using React Testing Library, so I’d recommend import `act` from RTL instead since it will get you the right version:

```ts
import { act } from '@testing-library/react';

```

---

<div class="post-metadata">

**Author:** ![stephan-buckmaster](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/stephan-buckmaster/32/5460_2.png) [@stephan-buckmaster](https://community.apollographql.com/u/stephan-buckmaster)\
**Post date:** [January 16, 2025, 10:31pm UTC](https://community.apollographql.com/t/testing-render-shows-deprecation-warning/8107/3 "2025-01-16T22:31:37Z")

</div>

Thanks! Here are the dependencies from package-lock.json

> “dependencies”: {  
> “@apollo/client”: “^3.11.10”,  
> “@apollo/react-testing”: “^4.0.0”,  
> “@testing-library/jest-dom”: “^5.17.0”,  
> “@testing-library/react”: “^13.4.0”,  
> “@testing-library/user-event”: “^13.5.0”,  
> “react”: “^18.3.1”,  
> “react-dom”: “^18.3.1”,  
> “react-scripts”: “5.0.1”,  
> “web-vitals”: “^2.1.4”  
> }

When I change to

> -import { React, act } from ‘react’; //-dom/test-utils";  
> +import { React } from ‘react’  
> import ‘@testing-library/jest-dom’  
> -import { render, screen } from ‘@testing-library/react’;  
> +import { render, screen, act } from ‘@testing-library/react’;

I get the same deprecation warning.

---

<div class="post-metadata">

**Author:** ![stephan-buckmaster](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/stephan-buckmaster/32/5460_2.png) [@stephan-buckmaster](https://community.apollographql.com/u/stephan-buckmaster)\
**Post date:** [January 16, 2025, 10:36pm UTC](https://community.apollographql.com/t/testing-render-shows-deprecation-warning/8107/4 "2025-01-16T22:36:32Z")

</div>

Wanted to be clear, the tests pass, but I would prefer to avoid the deprecation warnings especially because they come with a stack trace

---

<div class="post-metadata">

**Author:** ![jerelmiller](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jerelmiller/32/3314_2.png) [@jerelmiller](https://community.apollographql.com/u/jerelmiller)\
**Post date:** [January 16, 2025, 11:55pm UTC](https://community.apollographql.com/t/testing-render-shows-deprecation-warning/8107/5 "2025-01-16T23:55:19Z")

</div>

I think there are a couple things at play here:

Your React version is 18.3.1 which is the React 19 compat version with deprecation warnings to prepare you for React 19. You can see that in their upgrade guide here: [React 19 Upgrade Guide – React](https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-deprecated-react-dom-apis)

The version of RTL you’re using is a bit old at this point and my guess the import warnings comes from this library. [v16](https://github.com/testing-library/react-testing-library/releases/tag/v16.0.0) added support for React 19, and my guess the updated import was a part of this.

I’d suggest either downgrading React to 18.2 or try upgrading RTL to see if that fixes it.

---

<div class="post-metadata">

**Author:** ![stephan-buckmaster](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/stephan-buckmaster/32/5460_2.png) [@stephan-buckmaster](https://community.apollographql.com/u/stephan-buckmaster)\
**Post date:** [January 17, 2025, 2:58pm UTC](https://community.apollographql.com/t/testing-render-shows-deprecation-warning/8107/6 "2025-01-17T14:58:22Z")

</div>

Upgraded successfully, app still works, and tests pass without logs.

Here are the new versions:

> ```
> "@apollo/client": "^3.11.10",
> "@apollo/react-testing": "^4.0.0",
> "@testing-library/jest-dom": "^6.6.3",
> "@testing-library/react": "^16.2.0",
> "@testing-library/user-event": "^14.6.0",
> "react": "^19.0.0",
> "react-dom": "^19.0.0",
> "react-scripts": "5.0.1",
> 
> ```

Thanks @jerelmiller !
