Description
There was a test added as part of shallow renderer rewrite (#9426) in fc1c6f9 that I don’t understand.
It tests that you can take an instance, call cloneElement
on it, and pass the result to the shallow renderer. If we are doing this internally this seems like a misunderstanding of how the API should work, and we need to fix those callsites to read getRenderOutput()
instead of getMountedInstance()
.
You can see the test is wrong because if you change it to render to a different shallow renderer like this
const shallowRenderer = createRenderer();
let result = shallowRenderer.render(<SimpleComponent foo="foo" />);
expect(result).toEqual(<div>foo:bar</div>);
const instance = shallowRenderer.getMountedInstance();
const shallowRenderer2 = createRenderer();
const cloned = React.cloneElement(instance, {foo: 'baz'});
result = shallowRenderer2.render(cloned);
expect(result).toEqual(<div>baz:bar</div>);
it will fail with
TypeError: Cannot read property 'prototype' of undefined
The argument we’re passing in this case is not a proper React element and doesn’t actually have element.type
. It just mostly “happens” to work because both React elements and ShallowRenderer instances have .props
on them, and code almost doesn’t read anything else in the update path. This is an example hack that we needed because of this.
I think we should just delete this test, and fix the internal callsites. It was never intentionally supported, and prevents me from doing some other fixes in the shalllow renderer.