Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat exact props the same as shape #1610

Merged
merged 2 commits into from Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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