@@ -24,6 +24,14 @@ const parserOptions = {
2424// Tests
2525// ------------------------------------------------------------------------------
2626
27+ function stringsMessage ( str ) {
28+ return `Strings not allowed in JSX files: “${ str } ”` ;
29+ }
30+
31+ function jsxMessage ( str ) {
32+ return `Missing JSX expression container around literal string: “${ str } ”` ;
33+ }
34+
2735const ruleTester = new RuleTester ( { parserOptions} ) ;
2836ruleTester . run ( 'jsx-no-literals' , rule , {
2937
@@ -201,7 +209,7 @@ ruleTester.run('jsx-no-literals', rule, {
201209 }
202210 ` ,
203211 parser : 'babel-eslint' ,
204- errors : [ { message : 'Missing JSX expression container around literal string' } ]
212+ errors : [ { message : jsxMessage ( 'test' ) } ]
205213 } , {
206214 code : `
207215 class Comp1 extends Component {
@@ -211,7 +219,7 @@ ruleTester.run('jsx-no-literals', rule, {
211219 }
212220 ` ,
213221 parser : 'babel-eslint' ,
214- errors : [ { message : 'Missing JSX expression container around literal string' } ]
222+ errors : [ { message : jsxMessage ( 'test' ) } ]
215223 } , {
216224 code : `
217225 class Comp1 extends Component {
@@ -222,7 +230,7 @@ ruleTester.run('jsx-no-literals', rule, {
222230 }
223231 ` ,
224232 parser : 'babel-eslint' ,
225- errors : [ { message : 'Missing JSX expression container around literal string' } ]
233+ errors : [ { message : jsxMessage ( 'test' ) } ]
226234 } , {
227235 code : `
228236 class Comp1 extends Component {
@@ -233,7 +241,7 @@ ruleTester.run('jsx-no-literals', rule, {
233241 }
234242 ` ,
235243 parser : 'babel-eslint' ,
236- errors : [ { message : 'Missing JSX expression container around literal string' } ]
244+ errors : [ { message : jsxMessage ( 'test' ) } ]
237245 } , {
238246 code : `
239247 var Hello = createReactClass({
@@ -244,7 +252,7 @@ ruleTester.run('jsx-no-literals', rule, {
244252 });
245253 ` ,
246254 parser : 'babel-eslint' ,
247- errors : [ { message : 'Missing JSX expression container around literal string' } ]
255+ errors : [ { message : jsxMessage ( 'hello' ) } ]
248256 } , {
249257 code : `
250258 class Comp1 extends Component {
@@ -258,7 +266,7 @@ ruleTester.run('jsx-no-literals', rule, {
258266 }
259267 ` ,
260268 parser : 'babel-eslint' ,
261- errors : [ { message : 'Missing JSX expression container around literal string' } ]
269+ errors : [ { message : jsxMessage ( 'asdjfl' ) } ]
262270 } , {
263271 code : `
264272 class Comp1 extends Component {
@@ -274,7 +282,7 @@ ruleTester.run('jsx-no-literals', rule, {
274282 }
275283 ` ,
276284 parser : 'babel-eslint' ,
277- errors : [ { message : 'Missing JSX expression container around literal string' } ]
285+ errors : [ { message : jsxMessage ( 'asdjfl\n test\n foo' ) } ]
278286 } , {
279287 code : `
280288 class Comp1 extends Component {
@@ -290,7 +298,7 @@ ruleTester.run('jsx-no-literals', rule, {
290298 }
291299 ` ,
292300 parser : 'babel-eslint' ,
293- errors : [ { message : 'Missing JSX expression container around literal string' } ]
301+ errors : [ { message : jsxMessage ( 'test' ) } ]
294302 } , {
295303 code : `
296304 <Foo bar="test">
@@ -299,23 +307,23 @@ ruleTester.run('jsx-no-literals', rule, {
299307 ` ,
300308 parser : 'babel-eslint' ,
301309 options : [ { noStrings : true } ] ,
302- errors : [ { message : 'Strings not allowed in JSX files' } ]
310+ errors : [ { message : stringsMessage ( '\'Test\'' ) } ]
303311 } , {
304312 code : `
305313 <Foo bar="test">
306314 {'Test'}
307315 </Foo>
308316 ` ,
309317 options : [ { noStrings : true } ] ,
310- errors : [ { message : 'Strings not allowed in JSX files' } ]
318+ errors : [ { message : stringsMessage ( '\'Test\'' ) } ]
311319 } , {
312320 code : `
313321 <Foo bar="test">
314322 {'Test' + name}
315323 </Foo>
316324 ` ,
317325 options : [ { noStrings : true } ] ,
318- errors : [ { message : 'Strings not allowed in JSX files' } ]
326+ errors : [ { message : stringsMessage ( '\'Test\'' ) } ]
319327 } , {
320328 code : `
321329 <Foo bar="test">
@@ -324,55 +332,55 @@ ruleTester.run('jsx-no-literals', rule, {
324332 ` ,
325333 parser : 'babel-eslint' ,
326334 options : [ { noStrings : true } ] ,
327- errors : [ { message : 'Strings not allowed in JSX files' } ]
335+ errors : [ { message : stringsMessage ( 'Test' ) } ]
328336 } , {
329337 code : `
330338 <Foo bar="test">
331339 Test
332340 </Foo>
333341 ` ,
334342 options : [ { noStrings : true } ] ,
335- errors : [ { message : 'Strings not allowed in JSX files' } ]
343+ errors : [ { message : stringsMessage ( 'Test' ) } ]
336344 } , {
337345 code : `
338346 <Foo>
339347 {\`Test\`}
340348 </Foo>
341349 ` ,
342350 options : [ { noStrings : true } ] ,
343- errors : [ { message : 'Strings not allowed in JSX files' } ]
351+ errors : [ { message : stringsMessage ( '`Test`' ) } ]
344352 } , {
345353 code : '<Foo bar={`Test`} />' ,
346354 options : [ { noStrings : true } ] ,
347- errors : [ { message : 'Strings not allowed in JSX files' } ]
355+ errors : [ { message : stringsMessage ( '`Test`' ) } ]
348356 } , {
349357 code : '<Foo bar={`${baz}`} />' ,
350358 options : [ { noStrings : true } ] ,
351- errors : [ { message : 'Strings not allowed in JSX files' } ]
359+ errors : [ { message : stringsMessage ( '`${baz}`' ) } ]
352360 } , {
353361 code : '<Foo bar={`Test ${baz}`} />' ,
354362 options : [ { noStrings : true } ] ,
355- errors : [ { message : 'Strings not allowed in JSX files' } ]
363+ errors : [ { message : stringsMessage ( '`Test ${baz}`' ) } ]
356364 } , {
357365 code : '<Foo bar={`foo` + \'bar\'} />' ,
358366 options : [ { noStrings : true } ] ,
359367 errors : [
360- { message : 'Strings not allowed in JSX files' } ,
361- { message : 'Strings not allowed in JSX files' }
368+ { message : stringsMessage ( '`foo`' ) } ,
369+ { message : stringsMessage ( '\'bar\'' ) }
362370 ]
363371 } , {
364372 code : '<Foo bar={`foo` + `bar`} />' ,
365373 options : [ { noStrings : true } ] ,
366374 errors : [
367- { message : 'Strings not allowed in JSX files' } ,
368- { message : 'Strings not allowed in JSX files' }
375+ { message : stringsMessage ( '`foo`' ) } ,
376+ { message : stringsMessage ( '`bar`' ) }
369377 ]
370378 } , {
371379 code : '<Foo bar={\'foo\' + `bar`} />' ,
372380 options : [ { noStrings : true } ] ,
373381 errors : [
374- { message : 'Strings not allowed in JSX files' } ,
375- { message : 'Strings not allowed in JSX files' }
382+ { message : stringsMessage ( '\'foo\'' ) } ,
383+ { message : stringsMessage ( '`bar`' ) }
376384 ]
377385 }
378386 ]
0 commit comments