shallow->setProps: props not being set
See original GitHub issueCurrent behavior
When running setProps. This results in it not being set in the most simple of scenarios:
simplified down to a basic component / test
import React from 'react';
import {configure, shallow} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
const Component = ({prop1}) => <div>{prop1}</div>
describe.only('Component', () => {
it('should set the props', () => {
const component = shallow(<Component />);
component.setProps({prop1: 'prop1'});
expect(component.prop('prop1')).toEqual('prop1');
expect(component.props()).toEqual({prop1: 'prop1'});
});
});
result:
Expected behavior
shallow -> component
-> set props
-> props -> the props that were set
Your environment
Running this inside of jest (23.6.0) on Node (8.14.0).
API
- shallow
- mount
- render
Version
library | version |
---|---|
enzyme | 3.7.0 |
react | 16.3.0 |
react-dom | 16.3.0 |
react-test-renderer | n/a |
adapter (below) | 1.7.0 |
Adapter
- enzyme-adapter-react-16
- enzyme-adapter-react-16.3
- enzyme-adapter-react-16.2
- enzyme-adapter-react-16.1
- enzyme-adapter-react-15
- enzyme-adapter-react-15.4
- enzyme-adapter-react-14
- enzyme-adapter-react-13
- enzyme-adapter-react-helper
- others ( )
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
shallow->setProps: props not being set #1939 - GitHub
Current behavior When running setProps. This results in it not being set in the most simple of scenarios: simplified down to a basic ......
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 >"setProps()" not triggering "useEffect" in Jest - Stack Overflow
See useEffect not called when the component is shallow renderered and this issue. ... setProps({ userId }); expect(props.myAction).
Read more >Enzyme cheatsheet - Devhints
Shallow wrapping doesn't descend down to sub-components. A full mount also mounts sub-components. See: Shallow rendering, Full rendering. Debugging. console.
Read more >setProps(nextProps) | Enzyme - UNPKG
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 >
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
These answers don’t help. What is
.setProps()
for if it’s not expected to do anything?It certainly is expected to do something - it sets the props on the rendered element, not on the element whose
render
method is being evaluated. (for shallow)