Skip to content

Commit 3ac86d9

Browse files
authored
test: add unit tests (#101)
1 parent dd8c138 commit 3ac86d9

14 files changed

+122
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "Foo",
3+
"path": "arrow-function/component-with-default-value.tsx",
4+
"description": "",
5+
"properties": [
6+
{
7+
"name": "onClick",
8+
"type": "() => void | Promise<void>",
9+
"defaultValue": "() => {}",
10+
"optional": true
11+
}
12+
]
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface Props {
2+
onClick?: () => void | Promise<void>
3+
}
4+
5+
export const Foo = ({ onClick = () => {} }: Props) => {
6+
return <button onClick={onClick}>foo</button>
7+
}

packages/node-react-parser/src/__fixtures__/all-use-cases/arrow-function/component-with-documentation.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "Foo",
3+
"path": "arrow-function/component-with-global-deprecated.tsx",
4+
"description": "A Button component",
5+
"deprecated": true,
6+
"properties": []
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface Props {}
2+
3+
/**
4+
* A Button component
5+
* @deprecated
6+
*/
7+
export const Foo = () => {
8+
return <div>foo</div>
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "Foo",
3+
"path": "arrow-function/component-with-global-documentation.tsx",
4+
"description": "A Button component",
5+
"properties": [
6+
{
7+
"name": "children",
8+
"type": "React.ReactNode"
9+
}
10+
]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface Props {
2+
children: React.ReactNode
3+
}
4+
5+
/**
6+
* A Button component
7+
*/
8+
export function Foo({ children }: Props) {
9+
return <div>{children}</div>
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "Foo",
3+
"path": "arrow-function/component-with-optional.tsx",
4+
"description": "",
5+
"properties": [
6+
{
7+
"name": "onClick",
8+
"type": "() => void | Promise<void>",
9+
"optional": true
10+
}
11+
]
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface Props {
2+
onClick?: () => void | Promise<void>
3+
}
4+
5+
export const Foo = ({ onClick }: Props) => {
6+
return <button onClick={onClick}>foo</button>
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "Foo",
3+
"path": "arrow-function/component-with-property-deprecated.tsx",
4+
"description": "",
5+
"properties": [
6+
{
7+
"name": "variant",
8+
"type": "'primary' | 'black' | 'basic'",
9+
"deprecated": true
10+
}
11+
]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface Props {
2+
/** @deprecated */
3+
variant: 'primary' | 'black' | 'basic'
4+
}
5+
6+
export const Foo = ({ variant }: Props) => {
7+
return <div>{variant}</div>
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "Foo",
3+
"path": "arrow-function/component-with-property-documentation.tsx",
4+
"description": "",
5+
"properties": [
6+
{
7+
"name": "children",
8+
"type": "React.ReactNode",
9+
"description": "The content of the button"
10+
}
11+
]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface Props {
2+
/** The content of the button */
3+
children: React.ReactNode
4+
}
5+
6+
export const Foo = ({ children }: Props) => {
7+
return <div>{children}</div>
8+
}

packages/node-react-parser/src/__tests__/react-ast.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ describe('parseComponents', () => {
3434
'arrow-function/component-without-properties.tsx',
3535
'arrow-function/component-with-basic-properties.tsx',
3636
// 'arrow-function/default-exported-component.tsx', // TODO [Hacktoberfest] Implement for this test
37-
// 'arrow-function/component-with-documentation.tsx', // TODO [Hacktoberfest] Implement for this test
37+
'arrow-function/component-with-global-documentation.tsx',
38+
'arrow-function/component-with-property-documentation.tsx',
39+
'arrow-function/component-with-optional.tsx',
40+
'arrow-function/component-with-default-value.tsx',
41+
'arrow-function/component-with-property-deprecated.tsx',
42+
'arrow-function/component-with-global-deprecated.tsx',
3843
'variable-function/component-without-properties.tsx',
3944
'variable-function/component-with-basic-properties.tsx',
4045
'no-component/camel-case-function.tsx',

0 commit comments

Comments
 (0)