@@ -10,20 +10,47 @@ RuleTester.setDefaultConfig({
10
10
const ruleTester = new RuleTester ( ) ;
11
11
12
12
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'}/>" ;
15
13
const invalidExample = "import {Avatar} from 'module-with-deprecations'; const test = <Avatar url={'some_uri_string'}/>" ;
16
14
17
15
// NOTE: Deprecated components (not prop deprecation) will error at import and again if used as jsx tag.
18
16
ruleTester . run ( 'component-deprecation' , rule , {
19
17
valid : [
20
18
{
21
19
options : ruleOptions ,
22
- code : validExample ,
20
+ code : `
21
+ const Avatar = require('another-module').Avatar;
22
+ const test = <Avatar source={{uri: 'some_uri_string'}}/>;
23
+ ` ,
23
24
} ,
24
25
{
25
26
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/>` ,
27
54
} ,
28
55
] ,
29
56
invalid : [
@@ -63,9 +90,63 @@ ruleTester.run('component-deprecation', rule, {
63
90
} ,
64
91
{
65
92
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"/>` ,
68
97
errors : [ { message : "The 'Button' component's prop 'text' is deprecated. Please use the 'label' prop instead." } ] ,
69
98
} ,
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
+ // },
70
151
] ,
71
152
} ) ;
0 commit comments