Skip to content

Commit

Permalink
Merge pull request #5 from icd2k3/empty-array-required-fix
Browse files Browse the repository at this point in the history
Don't test empty array if array prop is required
  • Loading branch information
icd2k3 authored Feb 21, 2018
2 parents 303d23b + 6d9ee5a commit 394714f
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 232 deletions.
3 changes: 3 additions & 0 deletions examples/DeepProps/DeepProps.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';

const DeepProps = ({
optionalArray,
total,
users,
}) => (
Expand All @@ -17,13 +18,15 @@ const DeepProps = ({
))}
</div>
))}
{optionalArray && optionalArray.map(s => <span key={s}>s</span>)}
<span>
{total}
</span>
</div>
);

DeepProps.propTypes = {
optionalArray: PropTypes.arrayOf(PropTypes.string),
users: PropTypes.arrayOf(PropTypes.shape({
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
Expand Down
34 changes: 32 additions & 2 deletions examples/DeepProps/__tests__/__snapshots__/DeepProps.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`jest-auto-snapshots > DeepProps Matches snapshot when array prop "users" has one item: "[object Object]" 1`] = `
exports[`jest-auto-snapshots > DeepProps Matches snapshot when array prop "optionalArray" has one item: "jest-auto-snapshots String Fixture" 1`] = `
<div>
<div
key="jest-auto-snapshots String Fixture"
Expand All @@ -22,14 +22,39 @@ exports[`jest-auto-snapshots > DeepProps Matches snapshot when array prop "users
</span>
</div>
</div>
<span
key="jest-auto-snapshots String Fixture"
>
s
</span>
<span>
jest-auto-snapshots String Fixture
</span>
</div>
`;

exports[`jest-auto-snapshots > DeepProps Matches snapshot when array prop "users" is an empty array: "[]" 1`] = `
exports[`jest-auto-snapshots > DeepProps Matches snapshot when array prop "optionalArray" is an empty array: "[]" 1`] = `
<div>
<div
key="jest-auto-snapshots String Fixture"
>
<h1>
jest-auto-snapshots String Fixture
jest-auto-snapshots String Fixture
</h1>
<div
key="1"
>
<h2>
1
</h2>
<span>
$
jest-auto-snapshots String Fixture
</span>
</div>
</div>
<span>
jest-auto-snapshots String Fixture
</span>
Expand Down Expand Up @@ -58,6 +83,11 @@ exports[`jest-auto-snapshots > DeepProps Matches snapshot when passed all props
</span>
</div>
</div>
<span
key="jest-auto-snapshots String Fixture"
>
s
</span>
<span>
jest-auto-snapshots String Fixture
</span>
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-auto-snapshots",
"version": "2.1.0",
"version": "2.1.1",
"description": "Fully automated Jest snapshot tests for React components",
"main": "./dist/index.js",
"repository": "git@github.com:icd2k3/jest-auto-snapshots.git",
Expand All @@ -17,12 +17,12 @@
"dependencies": {
"caller-callsite": "^2.0.0",
"colors": "^1.1.2",
"react-docgen": "^2.20.0"
"react-docgen": "^2.20.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^8.0.3",
"babel-jest": "22.1.0",
"babel-eslint": "^8.2.2",
"babel-jest": "22.4.0",
"babel-plugin-dynamic-import-node": "^1.2.0",
"babel-plugin-module-alias": "^1.6.0",
"babel-preset-es2015": "^6.24.1",
Expand All @@ -32,14 +32,14 @@
"enzyme": "^3.2.0",
"enzyme-adapter-react-16": "^1.1.0",
"enzyme-to-json": "^3.2.2",
"eslint": "^4.12.1",
"eslint": "^4.18.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.5.1",
"eslint-plugin-react": "^7.7.0",
"esprima": "^4.0.0",
"eval": "^0.1.2",
"jest": "22.1.4",
"jest": "22.4.0",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const tests = (Component, { required, optional }) => {
const testPossibilities = possibilities(Component, allProps, key);
if (typeof allProps[key] === 'boolean') {
testPossibilities.boolean();
} else if (Array.isArray(allProps[key])) {
} else if (Array.isArray(allProps[key]) && !required[key]) {
testPossibilities.array();
}
});
Expand Down
Loading

0 comments on commit 394714f

Please sign in to comment.