Calling setProps() doesn't change props of children anymore
See original GitHub issueI 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:
- Created 6 years ago
- Reactions:14
- Comments:12 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
can you read comments before you add your comment?
It is an intended change in v3 to require you to re-find elements if you want changes reflected.