@@ -8,9 +8,10 @@ const ruleTester = avaRuleTester(test, {
88 }
99} ) ;
1010
11- function testCase ( code , name , error ) {
11+ function testCase ( code , name , error , output ) {
1212 return {
1313 code,
14+ output : output || code ,
1415 options : name ? [ { name} ] : [ ] ,
1516 errors : error ? [ { ruleId : 'catch-error-name' } ] : [ ]
1617 } ;
@@ -130,18 +131,19 @@ ruleTester.run('catch-error-name', rule, {
130131 // }
131132 // `),
132133 ] ,
134+
133135 invalid : [
134- testCase ( 'try {} catch (err) {}' , null , true ) ,
135- testCase ( 'try {} catch (error) {}' , 'err' , true ) ,
136+ testCase ( 'try {} catch (err) {}' , null , true , 'try {} catch (error) {}' ) ,
137+ testCase ( 'try {} catch (error) {}' , 'err' , true , 'try {} catch (err) {}' ) ,
136138 testCase ( 'try {} catch ({message}) {}' , null , true ) ,
137- testCase ( 'try {} catch (outerError) {}' , null , true ) ,
138- testCase ( 'try {} catch (innerError) {}' , null , true ) ,
139- testCase ( 'obj.catch(err => {})' , null , true ) ,
140- testCase ( 'obj.catch(error => {})' , 'err' , true ) ,
139+ testCase ( 'try {} catch (outerError) {}' , null , true , 'try {} catch (error) {}' ) ,
140+ testCase ( 'try {} catch (innerError) {}' , null , true , 'try {} catch (error) {}' ) ,
141+ testCase ( 'obj.catch(err => {})' , null , true , 'obj.catch(error => {})' ) ,
142+ testCase ( 'obj.catch(error => {})' , 'err' , true , 'obj.catch(err => {})' ) ,
141143 testCase ( 'obj.catch(({message}) => {})' , null , true ) ,
142- testCase ( 'obj.catch(function (err) {})' , null , true ) ,
144+ testCase ( 'obj.catch(function (err) {})' , null , true , 'obj.catch(function (error) {})' ) ,
143145 testCase ( 'obj.catch(function ({message}) {})' , null , true ) ,
144- testCase ( 'obj.catch(function (error) {})' , 'err' , true ) ,
146+ testCase ( 'obj.catch(function (error) {})' , 'err' , true , 'obj.catch(function (err) {})' ) ,
145147 // Failing tests for #107
146148 // testCase(`
147149 // foo.then(() => {
@@ -163,6 +165,15 @@ ruleTester.run('catch-error-name', rule, {
163165 }
164166 }
165167 ` ,
168+ output : `
169+ const handleError = error => {
170+ try {
171+ doSomething();
172+ } catch (error2) {
173+ console.log(error2);
174+ }
175+ }
176+ ` ,
166177 errors : [
167178 {
168179 ruleId : 'catch-error-name' ,
@@ -182,6 +193,17 @@ ruleTester.run('catch-error-name', rule, {
182193 }
183194 }
184195 ` ,
196+ output : `
197+ const handleError = error => {
198+ const error9 = new Error('foo bar');
199+
200+ try {
201+ doSomething();
202+ } catch (error2) {
203+ console.log(error2);
204+ }
205+ }
206+ ` ,
185207 errors : [
186208 {
187209 ruleId : 'catch-error-name' ,
@@ -197,6 +219,13 @@ ruleTester.run('catch-error-name', rule, {
197219 obj.catch(foo => { });
198220 }
199221 ` ,
222+ output : `
223+ const handleError = error => {
224+ const error2 = new Error('foo bar');
225+
226+ obj.catch(error3 => { });
227+ }
228+ ` ,
200229 errors : [
201230 {
202231 ruleId : 'catch-error-name' ,
@@ -212,6 +241,13 @@ ruleTester.run('catch-error-name', rule, {
212241 obj.catch(foo => { });
213242 }
214243 ` ,
244+ output : `
245+ const handleError = error => {
246+ const error2 = new Error('foo bar');
247+
248+ obj.catch(error3 => { });
249+ }
250+ ` ,
215251 errors : [
216252 {
217253 ruleId : 'catch-error-name' ,
@@ -229,13 +265,18 @@ ruleTester.run('catch-error-name', rule, {
229265 obj.catch(err => {});
230266 obj.catch(err => {});
231267 ` ,
268+ output : `
269+ obj.catch(error => {});
270+ obj.catch(error => {});
271+ ` ,
232272 errors : [
233273 { ruleId : 'catch-error-name' } ,
234274 { ruleId : 'catch-error-name' }
235275 ]
236276 } ,
237277 {
238278 code : 'try {} catch (_error) {}' ,
279+ output : 'try {} catch (error) {}' ,
239280 errors : [
240281 {
241282 ruleId : 'catch-error-name' ,
0 commit comments