Commit eea810d0 authored by Robert Knight's avatar Robert Knight

Validate prop types of mocked components

This adds basic runtime verification that mocked components are called
with types that are compatible with what the real component expects.

This turned up one existing issue with use of `MenuSection` by
`UserMenu`, where conditional rendering would cause the prop type check
to fail.
parent 52d8eed2
......@@ -38,8 +38,5 @@ MenuSection.propTypes = {
/**
* Menu items to display in this section.
*/
children: propTypes.oneOfType([
propTypes.object,
propTypes.arrayOf(propTypes.object),
]).isRequired,
children: propTypes.any.isRequired,
};
......@@ -59,8 +59,14 @@ export default function mockImportedComponents() {
}
const mock = props => props.children;
// Make it possible to do `wrapper.find('ComponentName')` where `wrapper`
// is an Enzyme wrapper.
mock.displayName = getDisplayName(value);
// Mocked components validate props in the same way as the real component.
mock.propTypes = value.propTypes;
return mock;
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment