@@ -2,47 +2,129 @@ import { applyTransform } from '@codeshift/test-utils';
22import * as transformer from './transform' ;
33
44describe ( 'react#remove-default-props transform' , ( ) => {
5- // it('should remove default props', async () => {
5+ // describe('components with function declaration', () => {
6+ // it('should move default props to function declaration when there no existing props', async () => {
67 // const result = await applyTransform(
78 // transformer,
89 // `
9- // import React from 'react';
10+ // import React from 'react';
11+ // export function Greet(){ <span>Hi {name}</span>; }
12+ // Greet.defaultProps = { name: 'Stranger' };
13+ // `,
14+ // { parser: 'tsx' },
15+ // );
16+ // expect(result).toMatchInlineSnapshot(`
17+ // import React from 'react'; export function Greet( { name: name = "Stranger"
18+ // } ) {
19+ // <span>Hi {name}</span>; }
20+ // `);
21+ // });
22+ // it('should remove default props and move them to intended place preserving other props', async () => {
23+ // const result = await applyTransform(
24+ // transformer,
25+ // `
26+ // import React from 'react';
27+ // export function Greet({text}){ <span>Hi {name} {text}</span>; }
28+ // Greet.defaultProps = { name: 'Stranger' };
29+ // `,
30+ // { parser: 'tsx' },
31+ // );
32+ // expect(result).toMatchInlineSnapshot(`
33+ // import React from 'react'; export function Greet( { text: text, name:
34+ // name = "Stranger" } ) {
35+ // <span>Hi {name} {text}</span>; }
36+ // `);
37+ // });
1038
11- // export const Greet = ({ name }) => <span>Hi {name}</span>;
39+ // it('should remove default props and move them to intended place preserving other props even with destructured renamed props', async () => {
40+ // const result = await applyTransform(
41+ // transformer,
42+ // `
43+ // import React from 'react';
44+ // export function Greet({text:myText}){ <span>Hi {name} {text}</span>; }
1245 // Greet.defaultProps = { name: 'Stranger' };
1346 // `,
1447 // { parser: 'tsx' },
1548 // );
16-
1749 // expect(result).toMatchInlineSnapshot(`
18- // import React from 'react'; export const Greet = ({ name }) =>
19- // <span>Hi {name}</span>;
20- // `);
50+ // import React from 'react'; export function Greet( { text: myText, name:
51+ // name = "Stranger" } ) {
52+ // <span>Hi {name} {text}</span>; }
53+ // `);
2154 // });
2255
23- it ( 'should replace default props for function component ' , async ( ) => {
24- const result = await applyTransform (
25- transformer ,
26- `
27- // import React from 'react';
28- // export const Greet = ({ name }) => <span>Hi {name}</span>;
29- // Greet.defaultProps = { name: 'Stranger' };
30- ` ,
31- { parser : 'tsx' } ,
32- ) ;
33-
34- expect ( result ) . toMatchInlineSnapshot ( `
35- // import React from 'react'; // export const Greet = ({ name }) =>
36- <span>Hi {name}</span>; // Greet.defaultProps = { name: 'Stranger' };
37- ` ) ;
38- } ) ;
56+ // it('preserves default values for destructured components ', async () => {
57+ // const result = await applyTransform(
58+ // transformer,
59+ // `
60+ // import React from 'react';
61+ // export function Greet({text:myText, props='amazingText'}){ <span>Hi {name} {text} </span>; }
62+ // Greet.defaultProps = { name: 'Stranger' };
63+ // `,
64+ // { parser: 'tsx' },
65+ // );
66+ // expect(result).toMatchInlineSnapshot(`
67+ // import React from 'react'; export function Greet( { text: myText, props:
68+ // props ='amazingText', name: name = "Stranger" } ) {
69+ // <span>Hi {name} {text} </span>; }
70+ // `);
71+ // });
3972
40- // it('should replace default props for arrow function component', async () => {
41- // const result = await applyTransform(transformer, input2, { parser: 'tsx' });
73+ // it(' with rest pworksarameters', async () => {
74+ // const result = await applyTransform(
75+ // transformer,
76+ // `
77+ // import React from 'react';
78+ // export function Greet({prop1,...someRest}){ <span>Hi {name} {text}</span>; }
79+ // Greet.defaultProps = { name: 'Stranger' };
80+ // `,
81+ // { parser: 'tsx' },
82+ // );
83+ // expect(result).toMatchInlineSnapshot(`
84+ // import React from 'react'; export function Greet( { prop1: prop1, name:
85+ // name = "Stranger", ...someRest } ) {
86+ // <span>Hi {name} {text}</span>; }
87+ // `);
88+ // });
4289
43- // expect(result).toMatchInlineSnapshot(`
44- // import React from 'react'; export const Component = () => { return
45- // <span>Hi {name}</span>; };
90+ // it('works with any props parameter passed', async () => {
91+ // const result = await applyTransform(
92+ // transformer,
93+ // `
94+ // import React from 'react';
95+ // export function Greet(props){ <span>Hi {name} {text}</span>; }
96+ // Greet.defaultProps = { name: 'Stranger' };
97+ // `,
98+ // { parser: 'tsx' },
99+ // );
100+ // expect(result).toMatchInlineSnapshot(`
101+ // import React from 'react'; export function Greet( { ...props, name: name
102+ // = "Stranger" } ) {
103+ // <span>Hi {name} {text}</span>; }
46104 // `);
105+ // });
47106 // });
107+
108+ describe ( 'components with as arrow functions' , ( ) => {
109+ it ( 'should remove default props' , async ( ) => {
110+ expect (
111+ await applyTransform (
112+ transformer ,
113+ `
114+ import React from 'react';
115+ export const Greet = ({ name }) => <span>Hi {name}</span>;
116+ Greet.defaultProps = { text: 'Stranger' };
117+ ` ,
118+ { parser : 'tsx' } ,
119+ ) ,
120+ ) . toMatchInlineSnapshot ( `
121+ "import React from 'react';
122+ export const Greet = (
123+ {
124+ text: text = \\"Stranger\\"
125+ }
126+ ) => {};"
127+ ` ) ;
128+ } ) ;
129+ } ) ;
48130} ) ;
0 commit comments