question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I can't call findByType on an instance (react-test-renderer)

See original GitHub issue

Bug

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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gaearoncommented, Aug 9, 2018

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.

2reactions
gaearoncommented, Aug 9, 2018

React 15 doesn’t provide this API.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found