@@ -33,7 +33,7 @@ ${body}}
3333` ;
3434}
3535
36- test ( 'validate react prop order' , ( t ) => {
36+ test ( 'validate react methods order' , ( t ) => {
3737 t . test ( 'make sure our eslintrc has React and JSX linting dependencies' , ( t ) => {
3838 t . plan ( 2 ) ;
3939 t . deepEqual ( reactRules . plugins , [ 'react' ] ) ;
@@ -44,6 +44,8 @@ test('validate react prop order', (t) => {
4444 t . plan ( 3 ) ;
4545 const result = lint ( wrapComponent ( `
4646 componentDidMount() {}
47+ handleSubmit() {}
48+ onButtonAClick() {}
4749 setFoo() {}
4850 getFoo() {}
4951 setBar() {}
@@ -88,4 +90,47 @@ test('validate react prop order', (t) => {
8890 t . ok ( result . errorCount , 'fails' ) ;
8991 t . deepEqual ( result . messages . map ( ( msg ) => msg . ruleId ) , [ 'react/sort-comp' ] , 'fails due to sort' ) ;
9092 } ) ;
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+ } ) ;
91136} ) ;
0 commit comments