From a612a1d65497f135c1e0e10fb16ab0d382a04fac Mon Sep 17 00:00:00 2001 From: Alesh Houdek Date: Mon, 22 Jun 2020 07:24:09 -0600 Subject: [PATCH] fix: Treat exact props the same as shape (#1610) --- .../rsg-components/Props/Props.spec.tsx | 72 +++++++++++++++++++ .../rsg-components/Props/renderExtra.tsx | 6 +- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/client/rsg-components/Props/Props.spec.tsx b/src/client/rsg-components/Props/Props.spec.tsx index a0280aabe..dbcf29791 100644 --- a/src/client/rsg-components/Props/Props.spec.tsx +++ b/src/client/rsg-components/Props/Props.spec.tsx @@ -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)']); @@ -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( [ @@ -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)']); @@ -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"])']); diff --git a/src/client/rsg-components/Props/renderExtra.tsx b/src/client/rsg-components/Props/renderExtra.tsx index d1dda6e6d..2f4d1e935 100644 --- a/src/client/rsg-components/Props/renderExtra.tsx +++ b/src/client/rsg-components/Props/renderExtra.tsx @@ -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;