Skip to content

Change props on same component instance, reprise #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eschiebel opened this issue Jan 22, 2019 · 2 comments
Closed

Change props on same component instance, reprise #273

eschiebel opened this issue Jan 22, 2019 · 2 comments

Comments

@eschiebel
Copy link

  • react-testing-library version:5.4.4
  • react version:16.7.0
  • node version: v8.10.0
  • npm (or yarn) version: yarn 10.1.1

Relevant code or config:

in a previously closed ticket #65 (comment) you suggest calling

render(<C {...newProps}/>, container)

to rerender with new props, but when I do this, the existing instance is not updated, but I get a new instance of the component.

What you did:

  1. set a breakpoint in my component's constructor, render, and componentDidUpdate functions
  2. call {{const {container} = render()}}
  3. The constructor and render breakpoints are hit. In render, I set window.xxx=this
  4. call render(<C value="177"/>, container)
  5. I see the constructor and render called. componentDidUpdate is not called and window.xxx!==this

What happened:

Reproduction:

https://codesandbox.io/s/jj56q52rqw

You can see that the test output renders 2 instances of the Hello component, and that componentDidUpdate is never called

Problem description:

I don't know how to test property change behavior on my components

Suggested solution:

@puemos
Copy link

puemos commented Jan 22, 2019

render(<Hello name="Jack" />, container);

probably needs to be:

render(<Hello name="Jack" />, {container});

https://codesandbox.io/s/okyw07246

@alexkrolick
Copy link
Collaborator

Thanks for catching that @puemos!

lucbpz pushed a commit to lucbpz/react-testing-library that referenced this issue Jul 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants