question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-test-renderer `update` method does not rerender component with new props

See original GitHub issue
  • react-hooks-testing-library version: 4.0.0
  • react-test-renderer version: 17.0.1
  • react version: 17.0.1
  • node version: 14.0.0
  • npm (or yarn) version: 1.22.5 (yarn)

Reproduction:

https://github.com/joshuaellis/react-test-renderer-update-issue

Problem description:

@testing-library/react-hooks rerender function uses react-test-renderer update under the hood. The props are correctly passed to update function but the hook does not re-render with the new props so the test fails.

image

Suggested solution:

I think this has something to do with react-test-renderer so i’ve raised it with them here but also want to keep an eye on it.

The expected behavior

the last two logs (in the image above) should say: “using func func2” “im func 2”

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mpeypercommented, Jan 8, 2021

Try making it

const { result, rerender } = renderHook(({ func }) =>
      usePolling({
        func,
        interval: 1000
      }),
      {
        initialProps: {
          func: func1
        }
      }
    )
0reactions
joshuaelliscommented, Jan 9, 2021

I’ll take a look, i’ve been trying to make my way through the issues we’ve got open and understand them properly 👍🏼

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: react-test-renderer `update` method does not rerender ...
The props are correctly passed to update function but the hook does not re-render with the new props so the test fails.
Read more >
React doesn't rerender on state change while testing
First add a test-id to your checkbox component like this : <input type="checkbox" checked={checkboxState} data-testid="checkboxID" />.
Read more >
Test Renderer - React
Re-render the in-memory tree with a new root element. This simulates a React update at the root. If the new element has the...
Read more >
Update Props of Render Component in React Testing Library
This proves that the rendered component does not remount when using the rerender function (i.e. a new instance of the rendered component is...
Read more >
Top 5 react-test-renderer Code Examples - Snyk
Learn more about how to use react-test-renderer, ... toEqual(['0']); }); // This update should not trigger a re-render renderer.act(() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found