I am seeing missing PropTypes warning during tests when using the `containsMatchingElement` API.
See original GitHub issueCurrent 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:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top 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 >
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
Ok perfect. This can probably be closed then. Thanks
Actually specifically I’d probably use
expect(wrapper.exists(AnotherComponent)).toBe(false)