Skip to content

Commit

Permalink
fix: Treat exact props the same as shape (#1610)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleshh committed Jun 22, 2020
1 parent a1a984a commit a612a1d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
72 changes: 72 additions & 0 deletions src/client/rsg-components/Props/Props.spec.tsx
Expand Up @@ -205,6 +205,21 @@ describe('props columns', () => {
`);
});

test('should render PropTypes.arrayOf(PropTypes.exact)', () => {
const { container } = renderJs([
'foos: PropTypes.arrayOf(PropTypes.exact({bar: PropTypes.number, baz: PropTypes.any}))',
]);

expect(getText(container)).toMatchInlineSnapshot(`
"Prop name: foos
Type: exact[]
Default:
Description:
bar : number
baz : any"
`);
});

test('should render PropTypes.instanceOf', () => {
const { container } = renderJs(['num: PropTypes.instanceOf(Number)']);

Expand All @@ -231,6 +246,21 @@ describe('props columns', () => {
`);
});

test('should render PropTypes.exact', () => {
const { container } = renderJs([
'foo: PropTypes.exact({bar: PropTypes.number.isRequired, baz: PropTypes.any})',
]);

expect(getText(container)).toMatchInlineSnapshot(`
"Prop name: foo
Type: exact
Default:
Description:
bar : number — Required
baz : any"
`);
});

test('should render PropTypes.shape with formatted defaultProps', () => {
const { getByText } = renderJs(
[
Expand Down Expand Up @@ -319,6 +349,28 @@ describe('props columns', () => {
`);
});

test('should render PropTypes.exact with description', () => {
const { container } = renderJs([
`foo: PropTypes.exact({
/**
* Number
*/
bar: PropTypes.number.isRequired,
/** Any */
baz: PropTypes.any
})`,
]);

expect(getText(container)).toMatchInlineSnapshot(`
"Prop name: foo
Type: exact
Default:
Description:
bar : number — Required — Number
baz : any — Any"
`);
});

test('should render PropTypes.objectOf', () => {
const { container } = renderJs(['colors: PropTypes.objectOf(PropTypes.string)']);

Expand Down Expand Up @@ -350,6 +402,26 @@ describe('props columns', () => {
`);
});

test('should render PropTypes.objectOf(PropTypes.exact)', () => {
const { container } = renderJs([
`colors: PropTypes.objectOf(
PropTypes.exact({
bar: PropTypes.number.isRequired,
baz: PropTypes.any
})
)`,
]);

expect(getText(container)).toMatchInlineSnapshot(`
"Prop name: colors
Type: {exact}
Default:
Description:
bar : number — Required
baz : any"
`);
});

test('should render PropTypes.oneOf', () => {
const { container } = renderJs(['size: PropTypes.oneOf(["small", "normal", "large"])']);

Expand Down
6 changes: 4 additions & 2 deletions src/client/rsg-components/Props/renderExtra.tsx
Expand Up @@ -71,13 +71,15 @@ export default function renderExtra(prop: PropDescriptor): React.ReactNode {
return renderUnion(type);
case 'shape':
return prop.type && renderShape(prop.type.value);
case 'exact':
return prop.type && renderShape(prop.type.value);
case 'arrayOf':
if (type.value.name === 'shape') {
if (type.value.name === 'shape' || type.value.name === 'exact') {
return prop.type && renderShape(prop.type.value.value);
}
return null;
case 'objectOf':
if (type.value.name === 'shape') {
if (type.value.name === 'shape' || type.value.name === 'exact') {
return prop.type && renderShape(prop.type.value.value);
}
return null;
Expand Down

0 comments on commit a612a1d

Please sign in to comment.