Add an end-to-end component test for App

Summary:
This should ensure that there aren’t any runtime PropTypes errors.

The change to reimplement `Object.entries` is due to the fact that my
local Node environment (v6.11.1) does not yet support that ESnext
function.

Test Plan:
Apply the following diff (`git apply`):
```diff
diff --git a/explorer/src/UserExplorer.js b/explorer/src/UserExplorer.js
index 8da252d..cdc1370 100644
--- a/explorer/src/UserExplorer.js
+++ b/explorer/src/UserExplorer.js
@@ -10,7 +10,7 @@ export class UserExplorer extends Component {
   static propTypes = {
     selectedPath: PropTypes.string.isRequired,
     selectedUser: PropTypes.string,
-    onSelectUser: PropTypes.func.isRequired,
+    onSelectUser: PropTypes.number.isRequired,
     data: commitUtilsPropTypes.commitData.isRequired,
   }
```
Then, `yarn test` should fail. Revert the diff, and `yarn test` should
pass.

wchargin-branch: react-proptypes-test
This commit is contained in:
William Chargin 2018-02-16 16:22:44 -08:00 committed by Dandelion Mané
parent 1d0368411c
commit c1b37fa729
2 changed files with 14 additions and 1 deletions

10
explorer/src/App.test.js Normal file
View File

@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
// Check that PropTypes check out.
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});

View File

@ -16,7 +16,10 @@ export class UserExplorer extends Component {
render() {
const weights = userWeightForPath(this.props.selectedPath, this.props.data, commitWeight);
const sortedUserWeightTuples = Object.entries(weights).sort((a,b) => b[1] - a[1]);
const sortedUserWeightTuples =
Object.keys(weights)
.map(k => [k, weights[k]])
.sort((a,b) => b[1] - a[1]);
const entries = sortedUserWeightTuples.map(authorWeight => {
const [author, weight] = authorWeight;
return <UserEntry userId={author} weight={weight} key={author}/>