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 am seeing missing PropTypes warning during tests when using the `containsMatchingElement` API.

See original GitHub issue

Current behavior

I am seeing missing PropTypes warning during tests when using the containsMatchingElement API.

Here is a minimal code example to get the warnings:

const AnotherComponent = ({ requiredProp }) => (
  <div>{requiredProp}</div>
);

AnotherComponent.propTypes = {
  exampleProp: PropTypes.string.isRequired
};

const MyComponent = () => {
  const someComputedValue = 'foo';
  return (
    <React.Fragment>
      <AnotherComponent someValue={ someComputedValue } />
    </React.Fragment>
  );
};

const wrapper = shallow(<MyComponent />);
expect(wrapper.containsMatchingElement(<AnotherComponent />)).toBe(true);

I can use expect(wrapper.find(AnotherComponent).length).toBe(1) but I’d really like to use the containsMatchingElement API in order to check other props are correct.

Any thoughts?

Expected behavior

I would like to not see these warnings.

API

  • shallow

Version

library version
enzyme 3.8.0
react 16.8.1
react-dom 16.8.1
react-test-renderer 16.8.1
adapter (below) 16

Adapter

  • enzyme-adapter-react-16

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
josh08hcommented, Mar 28, 2019

Ok perfect. This can probably be closed then. Thanks

1reaction
ljharbcommented, Mar 28, 2019

Actually specifically I’d probably use expect(wrapper.exists(AnotherComponent)).toBe(false)

Read more comments on GitHub >

github_iconTop Results From Across the Web

I am seeing missing PropTypes warning during tests ... - GitHub
Current behavior I am seeing missing PropTypes warning during tests when using the containsMatchingElement API.
Read more >
enzyme "containsMatchingElement" and missing PropTypes ...
Warning : Failed prop type: The prop `message2` is marked as required in `Son`, but its value is `undefined`. I know I could...
Read more >
Making unit tests fail when PropTypes error - Jack Franklin
Missing PropType warnings in test runs. When running our test suite with Jest, I noticed that I'd often miss the console warnings that...
Read more >
Don't Call PropTypes Warning - React
Don't call PropTypes directly. Using PropTypes in any other way than annotating React components with them is no longer supported: var apiShape =...
Read more >
props() · Enzyme - GitHub Pages
Returns the props object for the root node of the wrapper. It must be a single-node wrapper. NOTE: When called on a shallow...
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