-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(codemod): add tests to cover react default props codemod
- Loading branch information
1 parent
d9d281a
commit 1e6e60a
Showing
13 changed files
with
471 additions
and
1,008 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/codemod/test/fixtures/react-default-props/simple-arrow-function.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as PropTypes from 'prop-types'; | ||
|
||
const MyComponent = (props) => { | ||
return <div>{props.foo}</div>; | ||
}; | ||
MyComponent.defaultProps = { | ||
foo: 'bar', | ||
}; | ||
MyComponent.propTypes = { | ||
foo: PropTypes.string, | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/codemod/test/fixtures/react-default-props/simple-arrow-function.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type TMyComponentProps = { | ||
foo: string; | ||
}; | ||
|
||
const MyComponent = (props: TMyComponentProps) => { | ||
return <div>{props.foo}</div>; | ||
}; | ||
|
||
MyComponent.defaultProps = { | ||
foo: 'bar', | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/codemod/test/fixtures/react-default-props/simple-classic-function.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as PropTypes from 'prop-types'; | ||
|
||
function MyComponent(props) { | ||
return <div>{props.foo}</div>; | ||
} | ||
MyComponent.defaultProps = { | ||
foo: 'bar', | ||
}; | ||
MyComponent.propTypes = { | ||
foo: PropTypes.string, | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/codemod/test/fixtures/react-default-props/simple-classic-function.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type TMyComponentProps = { | ||
foo: string; | ||
}; | ||
|
||
function MyComponent(props: TMyComponentProps) { | ||
return <div>{props.foo}</div>; | ||
} | ||
|
||
MyComponent.defaultProps = { | ||
foo: 'bar', | ||
}; |
19 changes: 19 additions & 0 deletions
19
packages/codemod/test/fixtures/react-default-props/with-already-destructured-props.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as PropTypes from 'prop-types'; | ||
|
||
const MyComponent = ({ baz, ...props }) => { | ||
return ( | ||
<ul> | ||
<li>{props.foo}</li> | ||
<li>{props.bar}</li> | ||
<li>{baz}</li> | ||
</ul> | ||
); | ||
}; | ||
MyComponent.propTypes = { | ||
foo: PropTypes.string, | ||
bar: PropTypes.string, | ||
baz: PropTypes.string, | ||
}; | ||
MyComponent.defaultProps = { | ||
foo: 'bar', | ||
}; |
19 changes: 19 additions & 0 deletions
19
packages/codemod/test/fixtures/react-default-props/with-already-destructured-props.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
type TMyComponentProps = { | ||
foo: string; | ||
bar: string; | ||
baz: string; | ||
}; | ||
|
||
const MyComponent = ({ baz, ...props }: TMyComponentProps) => { | ||
return ( | ||
<ul> | ||
<li>{props.foo}</li> | ||
<li>{props.bar}</li> | ||
<li>{baz}</li> | ||
</ul> | ||
); | ||
}; | ||
|
||
MyComponent.defaultProps = { | ||
foo: 'bar', | ||
}; |
29 changes: 29 additions & 0 deletions
29
packages/codemod/test/fixtures/react-default-props/with-subcomponent.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as PropTypes from 'prop-types'; | ||
|
||
function MySubcomponent(props) { | ||
return ( | ||
<ul> | ||
<li>{props.foo}</li> | ||
<li>{props.bar}</li> | ||
</ul> | ||
); | ||
} | ||
MySubcomponent.propTypes = { | ||
foo: PropTypes.string, | ||
bar: PropTypes.string, | ||
}; | ||
|
||
function MyComponent(props) { | ||
return ( | ||
<div> | ||
<MySubcomponent {...props} /> | ||
</div> | ||
); | ||
} | ||
MyComponent.propTypes = { | ||
foo: PropTypes.string, | ||
bar: PropTypes.string, | ||
}; | ||
MyComponent.defaultProps = { | ||
foo: 'bar', | ||
}; |
27 changes: 27 additions & 0 deletions
27
packages/codemod/test/fixtures/react-default-props/with-subcomponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
type MySubcomponentProps = { | ||
foo: string; | ||
bar: string; | ||
}; | ||
function MySubcomponent(props: MySubcomponentProps) { | ||
return ( | ||
<ul> | ||
<li>{props.foo}</li> | ||
<li>{props.bar}</li> | ||
</ul> | ||
); | ||
} | ||
|
||
type TMyComponentProps = { | ||
foo: string; | ||
bar: string; | ||
}; | ||
function MyComponent(props: TMyComponentProps) { | ||
return ( | ||
<div> | ||
<MySubcomponent {...props} /> | ||
</div> | ||
); | ||
} | ||
MyComponent.defaultProps = { | ||
foo: 'bar', | ||
}; |
Oops, something went wrong.