Skip to content

Commit 0f59d01

Browse files
MrHensindresorhus
authored andcommitted
Use outdent for multiline test cases (#320)
1 parent 5ed0e1f commit 0f59d01

13 files changed

+1269
-1042
lines changed

test/catch-error-name.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test from 'ava';
22
import avaRuleTester from 'eslint-ava-rule-tester';
3+
import {outdent} from 'outdent';
34
import rule from '../rules/catch-error-name';
45

56
const ruleTester = avaRuleTester(test, {
@@ -24,7 +25,7 @@ ruleTester.run('catch-error-name', rule, {
2425
testCase('try {} catch (_) { console.log(foo); }'),
2526
testCase('try {} catch (err) {}', 'err'),
2627
testCase('try {} catch (outerError) { try {} catch (innerError) {} }'),
27-
testCase(`
28+
testCase(outdent`
2829
const handleError = error => {
2930
try {
3031
doSomething();
@@ -33,7 +34,7 @@ ruleTester.run('catch-error-name', rule, {
3334
}
3435
}
3536
`),
36-
testCase(`
37+
testCase(outdent`
3738
const handleError = err => {
3839
try {
3940
doSomething();
@@ -42,7 +43,7 @@ ruleTester.run('catch-error-name', rule, {
4243
}
4344
}
4445
`, 'err'),
45-
testCase(`
46+
testCase(outdent`
4647
const handleError = error => {
4748
const error_ = new Error('🦄');
4849
@@ -54,24 +55,24 @@ ruleTester.run('catch-error-name', rule, {
5455
}
5556
`),
5657
testCase('obj.catch(error => {})'),
57-
testCase(`
58+
testCase(outdent`
5859
const handleError = error => {
5960
obj.catch(error_ => { });
6061
}
6162
`),
62-
testCase(`
63+
testCase(outdent`
6364
const handleError = err => {
6465
obj.catch(err_ => { });
6566
}
6667
`, 'err'),
67-
testCase(`
68+
testCase(outdent`
6869
const handleError = error => {
6970
const error_ = new Error('foo bar');
7071
7172
obj.catch(error__ => { });
7273
}
7374
`),
74-
testCase(`
75+
testCase(outdent`
7576
const handleError = error => {
7677
const error_ = new Error('foo bar');
7778
const error__ = new Error('foo bar');
@@ -104,7 +105,7 @@ ruleTester.run('catch-error-name', rule, {
104105
testCase('try {} catch (_) {}'),
105106
testCase('try {} catch (_) { try {} catch (_) {} }'),
106107
testCase('try {} catch (_) { console.log(_); }'),
107-
testCase(`
108+
testCase(outdent`
108109
const handleError = error => {
109110
try {
110111
doSomething();
@@ -123,7 +124,7 @@ ruleTester.run('catch-error-name', rule, {
123124
]
124125
}
125126
// TODO: Uncomment once test runner supports optional-catch-binding https://github.com/tc39/proposal-optional-catch-binding
126-
// testCase(`
127+
// testCase(outdent`
127128
// try {
128129
// throw new Error('message');
129130
// } catch {
@@ -145,18 +146,18 @@ ruleTester.run('catch-error-name', rule, {
145146
testCase('obj.catch(function ({message}) {})', null, true),
146147
testCase('obj.catch(function (error) { console.log(error) })', 'err', true, 'obj.catch(function (err) { console.log(err) })'),
147148
// Failing tests for #107
148-
// testCase(`
149+
// testCase(outdent`
149150
// foo.then(() => {
150151
// try {} catch (e) {}
151152
// }).catch(error => error);
152153
// `, null, true),
153-
// testCase(`
154+
// testCase(outdent`
154155
// foo.then(() => {
155156
// try {} catch (e) {}
156157
// });
157158
// `, null, true),
158159
{
159-
code: `
160+
code: outdent`
160161
const handleError = error => {
161162
try {
162163
doSomething();
@@ -165,7 +166,7 @@ ruleTester.run('catch-error-name', rule, {
165166
}
166167
}
167168
`,
168-
output: `
169+
output: outdent`
169170
const handleError = error => {
170171
try {
171172
doSomething();
@@ -182,7 +183,7 @@ ruleTester.run('catch-error-name', rule, {
182183
]
183184
},
184185
{
185-
code: `
186+
code: outdent`
186187
const handleError = error => {
187188
try {
188189
doSomething();
@@ -191,7 +192,7 @@ ruleTester.run('catch-error-name', rule, {
191192
}
192193
}
193194
`,
194-
output: `
195+
output: outdent`
195196
const handleError = error => {
196197
try {
197198
doSomething();
@@ -208,7 +209,7 @@ ruleTester.run('catch-error-name', rule, {
208209
]
209210
},
210211
{
211-
code: `
212+
code: outdent`
212213
const handleError = error => {
213214
const error9 = new Error('foo bar');
214215
@@ -219,7 +220,7 @@ ruleTester.run('catch-error-name', rule, {
219220
}
220221
}
221222
`,
222-
output: `
223+
output: outdent`
223224
const handleError = error => {
224225
const error9 = new Error('foo bar');
225226
@@ -238,14 +239,14 @@ ruleTester.run('catch-error-name', rule, {
238239
]
239240
},
240241
{
241-
code: `
242+
code: outdent`
242243
const handleError = error => {
243244
const error_ = new Error('foo bar');
244245
245246
obj.catch(foo => { });
246247
}
247248
`,
248-
output: `
249+
output: outdent`
249250
const handleError = error => {
250251
const error_ = new Error('foo bar');
251252
@@ -260,14 +261,14 @@ ruleTester.run('catch-error-name', rule, {
260261
]
261262
},
262263
{
263-
code: `
264+
code: outdent`
264265
const handleError = error => {
265266
const error_ = new Error('foo bar');
266267
267268
obj.catch(foo => { });
268269
}
269270
`,
270-
output: `
271+
output: outdent`
271272
const handleError = error => {
272273
const error_ = new Error('foo bar');
273274
@@ -287,11 +288,11 @@ ruleTester.run('catch-error-name', rule, {
287288
]
288289
},
289290
{
290-
code: `
291+
code: outdent`
291292
obj.catch(err => {});
292293
obj.catch(err => {});
293294
`,
294-
output: `
295+
output: outdent`
295296
obj.catch(error => {});
296297
obj.catch(error => {});
297298
`,

0 commit comments

Comments
 (0)