Skip to content

Commit b7c32c3

Browse files
committed
Add more tests for component deprecation (commented for now)
1 parent 30dcb60 commit b7c32c3

File tree

2 files changed

+92
-6
lines changed

2 files changed

+92
-6
lines changed

eslint-rules/tests/component_deprecation.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@
3232
"component": "List.Part",
3333
"source": "module-with-deprecations",
3434
"message": "Please use the 'List.Item' component instead."
35+
},
36+
{
37+
"component": "List",
38+
"source": "another-module-with-deprecations",
39+
"message": "Please use the 'ListList' component instead."
3540
}
3641
]

eslint-rules/tests/lib/rules/component-deprecation.js

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,47 @@ RuleTester.setDefaultConfig({
1010
const ruleTester = new RuleTester();
1111

1212
const ruleOptions = [{deprecations: deprecationsJson}];
13-
const validExample = "const test = <Avatar source={{uri: 'some_uri_string'}}/>";
14-
const validImportExample = "import {Avatar} from 'another-module'; const test = <Avatar url={'some_uri_string'}/>";
1513
const invalidExample = "import {Avatar} from 'module-with-deprecations'; const test = <Avatar url={'some_uri_string'}/>";
1614

1715
// NOTE: Deprecated components (not prop deprecation) will error at import and again if used as jsx tag.
1816
ruleTester.run('component-deprecation', rule, {
1917
valid: [
2018
{
2119
options: ruleOptions,
22-
code: validExample,
20+
code: `
21+
const Avatar = require('another-module').Avatar;
22+
const test = <Avatar source={{uri: 'some_uri_string'}}/>;
23+
`,
2324
},
2425
{
2526
options: ruleOptions,
26-
code: validImportExample,
27+
code: `
28+
const {Avatar, List} = require('another-module');
29+
const test = <Avatar source={{uri: 'some_uri_string'}}/>;
30+
`,
31+
},
32+
{
33+
options: ruleOptions,
34+
code: `
35+
const module = require('another-module');
36+
const {Avatar, TextField} = module;
37+
const test1 = <Avatar source={{uri: 'some_uri_string'}}/>;
38+
const test2 = <TextField>Bla</TextField>;
39+
`,
40+
},
41+
{
42+
options: ruleOptions,
43+
code: `
44+
import {Avatar, TextField} from 'another-module';
45+
const test1 = <Avatar url={'some_uri_string'}/>;
46+
const test2 = <TextField>Bla</TextField>;
47+
`,
48+
},
49+
{
50+
options: ruleOptions,
51+
code: `
52+
import {List} from 'module-with-deprecations';
53+
<List/>`,
2754
},
2855
],
2956
invalid: [
@@ -63,9 +90,63 @@ ruleTester.run('component-deprecation', rule, {
6390
},
6491
{
6592
options: ruleOptions,
66-
code:
67-
'import {Button} from \'module-with-deprecations\'; const props = {text: "button", color: "red"}; <Button {...props} value="value"/>', // eslint-disable-line
93+
code: `
94+
import {Button} from 'module-with-deprecations';
95+
const props = {text: "button", color: "red"};
96+
<Button {...props} value="value"/>`,
6897
errors: [{message: "The 'Button' component's prop 'text' is deprecated. Please use the 'label' prop instead."}],
6998
},
99+
// {
100+
// options: ruleOptions,
101+
// code: `
102+
// import {Button as B} from 'module-with-deprecations';
103+
// const props = {text: "button", color: "red"};
104+
// <B {...props} value="value"/>`,
105+
// errors: [{message: "The 'Button' component's prop 'text' is deprecated. Please use the 'label' prop instead."}],
106+
// },
107+
// {
108+
// options: ruleOptions,
109+
// code: `
110+
// import * as module from 'module-with-deprecations';
111+
// const {Button} = module;
112+
// const props = {text: "button", color: "red"};
113+
// <Button {...props} value="value"/>`,
114+
// errors: [{message: "The 'Button' component's prop 'text' is deprecated. Please use the 'label' prop instead."}],
115+
// },
116+
// {
117+
// options: ruleOptions,
118+
// code: `
119+
// import * as module from 'module-with-deprecations';
120+
// const props = {text: "button", color: "red"};
121+
// <module.Button {...props} value="value"/>`,
122+
// errors: [{message: "The 'Button' component's prop 'text' is deprecated. Please use the 'label' prop instead."}],
123+
// },
124+
// {
125+
// options: ruleOptions,
126+
// code: `
127+
// import * as module from 'module-with-deprecations';
128+
// <module.List.Part/>`,
129+
// errors: [{message: "The 'List.Part' component is deprecated. Please use the 'List.Item' component instead."}],
130+
// },
131+
// {
132+
// options: ruleOptions,
133+
// code: `
134+
// import {List} from 'another-module-with-deprecations';
135+
// <List/>`,
136+
// errors: [{message: "The 'List' component is deprecated. Please use the 'ListList' component instead."}],
137+
// },
138+
// {
139+
// options: ruleOptions,
140+
// code: `
141+
// import {View, Button, TextInput} from 'module-with-deprecations';
142+
// <View>
143+
// <Button text="my button"/>
144+
// <TextInput placeholder="first name"/>
145+
// </View>`,
146+
// errors: [
147+
// {message: "The 'TextInput' component is deprecated. Please use the 'TextField' component instead."},
148+
// {message: "The 'TextInput' component is deprecated. Please use the 'TextField' component instead."},
149+
// {message: "The 'Button' component's prop 'text' is deprecated. Please use the 'label' prop instead."}],
150+
// },
70151
],
71152
});

0 commit comments

Comments
 (0)