@@ -33,7 +33,7 @@ ${body}}
33
33
` ;
34
34
}
35
35
36
- test ( 'validate react prop order' , ( t ) => {
36
+ test ( 'validate react methods order' , ( t ) => {
37
37
t . test ( 'make sure our eslintrc has React and JSX linting dependencies' , ( t ) => {
38
38
t . plan ( 2 ) ;
39
39
t . deepEqual ( reactRules . plugins , [ 'react' ] ) ;
@@ -44,6 +44,8 @@ test('validate react prop order', (t) => {
44
44
t . plan ( 3 ) ;
45
45
const result = lint ( wrapComponent ( `
46
46
componentDidMount() {}
47
+ handleSubmit() {}
48
+ onButtonAClick() {}
47
49
setFoo() {}
48
50
getFoo() {}
49
51
setBar() {}
@@ -88,4 +90,47 @@ test('validate react prop order', (t) => {
88
90
t . ok ( result . errorCount , 'fails' ) ;
89
91
t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
90
92
} ) ;
93
+
94
+ t . test ( 'order: when handler method with `handle` prefix after method with `on` prefix' , ( t ) => {
95
+ t . plan ( 2 ) ;
96
+ const result = lint ( wrapComponent ( `
97
+ componentDidMount() {}
98
+ onButtonAClick() {}
99
+ handleSubmit() {}
100
+ setFoo() {}
101
+ getFoo() {}
102
+ render() { return <div />; }
103
+ ` ) ) ;
104
+
105
+ t . ok ( result . errorCount , 'fails' ) ;
106
+ t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
107
+ } ) ;
108
+
109
+ t . test ( 'order: when lifecycle methods after event handler methods' , ( t ) => {
110
+ t . plan ( 2 ) ;
111
+ const result = lint ( wrapComponent ( `
112
+ handleSubmit() {}
113
+ componentDidMount() {}
114
+ setFoo() {}
115
+ getFoo() {}
116
+ render() { return <div />; }
117
+ ` ) ) ;
118
+
119
+ t . ok ( result . errorCount , 'fails' ) ;
120
+ t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
121
+ } ) ;
122
+
123
+ t . test ( 'order: when event handler methods after getters and setters' , ( t ) => {
124
+ t . plan ( 2 ) ;
125
+ const result = lint ( wrapComponent ( `
126
+ componentDidMount() {}
127
+ setFoo() {}
128
+ getFoo() {}
129
+ handleSubmit() {}
130
+ render() { return <div />; }
131
+ ` ) ) ;
132
+
133
+ t . ok ( result . errorCount , 'fails' ) ;
134
+ t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
135
+ } ) ;
91
136
} ) ;
0 commit comments