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.

Calling setProps() doesn't change props of children anymore

See original GitHub issue

I just switched to Enzyme v3 with React v15.6 and I could notice that setProps() doesn’t change props of children anymore. Instead, it only changes props of wrapper:

Config

{
    "enzyme":"^3.1.0",
    "enzyme-adapter-react-15":"^1.0.1",
    "jest":"^21.2.1",
    "react":"^15.6.2",
    "react-dom":"^15.6.2",
    "react-test-renderer":"^15.6.2"
}

Test

import React from 'react'
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-15'

Enzyme.configure({ adapter: new Adapter() })

const Child = () => null
const Parent = props => <Child test={props.test} />

it('should update prop test', () => {
    const parent = Enzyme.mount(<Parent test="foo" />)
    const child = parent.find(Child)

    expect(parent.prop('test')).toBe('foo') // true (foo)
    expect(child.prop('test')).toBe('foo') // true (foo)

    parent.setProps({ test: 'bar' })

    expect(parent.prop('test')).toBe('bar') // true (bar)
    expect(child.prop('test')).toBe('bar') // false (foo)
})

The above test works with Enzyme v2.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:14
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

47reactions
Keprocommented, Feb 28, 2018

can you read comments before you add your comment?

35reactions
ljharbcommented, Oct 7, 2017

It is an intended change in v3 to require you to re-find elements if you want changes reflected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"setProps()" not triggering "useEffect" in Jest - Stack Overflow
However it's updating props in myComp. Component Example: const myComp = ({userId, myAction}) => { useEffect( ...
Read more >
Why React Child Components Don't Update on Prop Changes
In React, it's a common problem to have child components that don't re-render when you expect them to. In particular, a common problems...
Read more >
setProps(nextProps) · Enzyme - GitHub Pages
A method that sets the props of the root component, and re-renders. Useful for when you are wanting to test how the component...
Read more >
and how to pass props to components in React . (part_1)
Passing only props from component to component doesn't make the component interactive, because nothing is there to change the props.
Read more >
React for Python Developers: a primer - Dash Plotly
You will need python to generate your components classes to work with Dash. ... In the constructor, we call the super() method on...
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