Skip to content

Commit

Permalink
100% test coverage and corresponding fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
reklawnos authored and ljharb committed Jun 15, 2018
1 parent 23f201c commit 61d968f
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 83 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
@@ -0,0 +1,2 @@
dist/**
coverage/**
2 changes: 2 additions & 0 deletions jest.config.js
Expand Up @@ -5,4 +5,6 @@ module.exports = {
setupTestFrameworkScriptFile: './test/_helpers.jsx',
testEnvironment: 'node',
testRegex: '.*(\\.|/|_)(test)\\.jsx?$',
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{js,jsx}'],
};
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -7,7 +7,7 @@
"clean": "rimraf dist",
"prebuild": "npm run clean",
"build": "babel src --out-dir dist",
"lint": "eslint --ignore-pattern 'dist/' .",
"lint": "eslint .",
"test": "jest",
"prepublish": "safe-publish-latest && npm run build"
},
Expand Down Expand Up @@ -41,7 +41,7 @@
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.8.2",
"jest": "^22.4.3",
"jest": "^23.1.0",
"prop-types": "^15.6.1",
"react": "^0.14 || ^15 || ^16",
"react-dom": "^0.14 || ^15 || ^16",
Expand Down
10 changes: 7 additions & 3 deletions src/index.js
Expand Up @@ -19,8 +19,8 @@ export default function createHOC(
{
passedProps = [],
factory,
allowExtraProps,
} = {},
allowExtraProps = false,
},
) {
if (!hocName || typeof hocName !== 'string') {
throw new Error('A valid name for this HOC must be passed.');
Expand Down Expand Up @@ -60,14 +60,18 @@ export default function createHOC(

const newPropTypes = {
...copiedProps,
...NewComponent.propTypes,
...(NewComponent.propTypes && sloppy(NewComponent.propTypes)),
};

if (allowExtraProps) {
NewComponent.propTypes = newPropTypes;
} else {
NewComponent.propTypes = exact(newPropTypes);
}
} else if (!allowExtraProps) {
// Get "sloppy" propTypes before getting "exact" prop types in case
// the original prop types were already "exact"
NewComponent.propTypes = exact(sloppy(NewComponent.propTypes));
}

return hoistNonReactStatics(NewComponent, ComponentToWrap);
Expand Down
9 changes: 8 additions & 1 deletion test/fixtures/BasicSFC.jsx → test/fixtures.jsx
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

export default function BasicSFC({ a, b, c }) {
export function BasicSFC({ a, b, c }) {
return (
<div>
<div id="a">{a}</div>
Expand All @@ -16,3 +16,10 @@ BasicSFC.propTypes = {
b: PropTypes.string.isRequired,
c: PropTypes.string.isRequired,
};


export function ProplessSFC() {
return (
<div>Wow!</div>
);
}

0 comments on commit 61d968f

Please sign in to comment.