Skip to content

Commit

Permalink
Merge pull request #155 from hypothesis/remove-prop-types
Browse files Browse the repository at this point in the history
Remove remaining prop-types usage
  • Loading branch information
robertknight authored Jul 26, 2021
2 parents 20f9a46 + 5a02542 commit f4cd377
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"postcss": "^8.2.13",
"preact": "^10.4.0",
"prettier": "^2.2.1",
"prop-types": "^15.7.2",
"puppeteer": "^7.1.0",
"sass": "^1.32.11",
"sinon": "^9.0.0",
Expand Down
8 changes: 0 additions & 8 deletions src/components/SvgIcon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import classnames from 'classnames';
import { useLayoutEffect, useRef } from 'preact/hooks';
import propTypes from 'prop-types';

/**
* Object mapping icon names to SVG markup.
Expand Down Expand Up @@ -76,13 +75,6 @@ export function SvgIcon({ name, className = '', inline = false, title = '' }) {
);
}

SvgIcon.propTypes = {
name: propTypes.string.isRequired,
className: propTypes.string,
inline: propTypes.bool,
title: propTypes.string,
};

/**
* Register icons for use with the `SvgIcon` component.
*
Expand Down
1 change: 0 additions & 1 deletion src/hooks/test/use-element-should-close-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('useElementShouldClose', () => {
];

// Create a fake component to mount in tests that uses the hook
// eslint-disable-next-line react/prop-types
function FakeComponent({ isOpen = true }) {
const myRef = useRef();
useElementShouldClose(myRef, isOpen, handleClose);
Expand Down
17 changes: 11 additions & 6 deletions test/util/mock-imported-components.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/**
* Return true if `value` "looks like" a React/Preact component.
* Return true if an imported `value` "looks like" a Preact function component.
*
* This check can have false positives (ie. match values which are not really components).
* That's OK because typical usage in a test is to first mock all components with
* `$imports.$mock(mockImportedComponents())` and then mock other things with
* `$imports.$mock(...)`. The more specific mocks will override the generic
* component mocks.
*/
function isComponent(value) {
return (
typeof value === 'function' &&
Object.prototype.hasOwnProperty.call(value, 'propTypes') &&
value.name.match(/^[A-Z]/)
value.name.match(/^[A-Z]/) &&
// Check that function is not an ES class. Note this only works with real
// ES classes and may not work with ones transpiled to ES5.
!value.toString().match(/^class\b/)
);
}

Expand Down Expand Up @@ -64,9 +72,6 @@ export default function mockImportedComponents() {
// 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;
};
}

0 comments on commit f4cd377

Please sign in to comment.