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:

shallow -> component
-> set props
-> props -> the props that were set
Running this inside of jest (23.6.0) on Node (8.14.0).
| 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
This is because you're confused about what the wrapper is - it's not Component, it's what component renders - in this case, a div with no props.
@ljharb
From docs:
shallow(node[, options]) => ShallowWrapper, ShallowWrapper: The wrapper instance around the rendered output.
...'it's not Component, it's what component renders'
@pablo-bl right - the rendered output. The docs agree with my comment.
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)
Most helpful comment
These answers don't help. What is
.setProps()for if it's not expected to do anything?