I can't call findByType on an instance (react-test-renderer)
See original GitHub issueBug
What is the current behavior? I can’t call findByType() on an instance
TypeError: instance.findByType is not a function
140 |
141 | let instance = testRenderer.getInstance();
> 142 | let fieldMapper = instance.findByType(FieldMapper)
What is the expected behavior? I want to get FieldMapper componen which is a child of FieldMapping
This is the peace of code from the test
testRenderer = create(
<Provider store={store}>
<FieldMapping
setStage={(stage: number) => { }}
spDataProvider={null}
msFlowApprovalUrl=""
></FieldMapping>
</Provider>
);
let instance = testRenderer.getInstance();
let fieldMapper = instance.findByType(FieldMapper)
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React? React 15.6.2 react-test-renderer 15.6.2 Typescript 2.4.2 @types/react-test-renderer 16.0.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Why can react-test-renderer only findByType functional ...
In the real-world scenario that these Some ... test files were created to solve, the problem was caused by React's memo() function:
Read more >Test Renderer - React
Example : import TestRenderer from 'react-test-renderer'; ... Use this version of act() to wrap calls to TestRenderer.create and ... findByType(type).
Read more >react-test-renderer.ReactTestInstance.findByType JavaScript ...
[ 4 ] get BtnGroup element by node type const element = instance.findByType("div");
Read more >How to use React Test Renderer to test React components
props} />).root; // get element by component name const element = instance.findByType("div"); // assert if an additional className was added to existing one ......
Read more >TDD with React Test Renderer - LogRocket Blog
root; // get element by component name const element = instance.findByType("div"); // assert if an additional className ...
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

We only have documentations for past versions starting with 16.0, sorry.
You can try looking here but it’s likely missing test renderer because it was too new at that point, and not documented yet: https://github.com/facebook/react/tree/15-stable/docs/docs
But in any case, test renderer didn’t have any traversal API in 15.x. So finding something by type or otherwise traversing the hierarchy just can’t be done in 15 without using private APIs like Enzyme did.
React 15 doesn’t provide this API.