Skip to content

Commit d5d5e34

Browse files
committed
Rewrite require-render-return tests with template literals
1 parent 4d62834 commit d5d5e34

File tree

1 file changed

+105
-120
lines changed

1 file changed

+105
-120
lines changed

tests/lib/rules/require-render-return.js

Lines changed: 105 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -30,161 +30,146 @@ const ruleTester = new RuleTester({parserOptions});
3030
ruleTester.run('require-render-return', rule, {
3131

3232
valid: [{
33-
// ES6 class
34-
code: [
35-
'class Hello extends React.Component {',
36-
' render() {',
37-
' return <div>Hello {this.props.name}</div>;',
38-
' }',
39-
'}'
40-
].join('\n')
33+
code: `
34+
class Hello extends React.Component {
35+
render() {
36+
return <div>Hello {this.props.name}</div>;
37+
}
38+
}
39+
`
4140
}, {
42-
// ES6 class with render property
43-
code: [
44-
'class Hello extends React.Component {',
45-
' render = () => {',
46-
' return <div>Hello {this.props.name}</div>;',
47-
' }',
48-
'}'
49-
].join('\n'),
41+
code: `
42+
class Hello extends React.Component {
43+
render = () => {
44+
return <div>Hello {this.props.name}</div>;
45+
}
46+
}
47+
`,
5048
parser: 'babel-eslint'
5149
}, {
52-
// ES6 class with render property (implicit return)
53-
code: [
54-
'class Hello extends React.Component {',
55-
' render = () => (',
56-
' <div>Hello {this.props.name}</div>',
57-
' )',
58-
'}'
59-
].join('\n'),
50+
code: `
51+
class Hello extends React.Component {
52+
render = () => (
53+
<div>Hello {this.props.name}</div>
54+
)
55+
}
56+
`,
6057
parser: 'babel-eslint'
6158
}, {
62-
// ES5 class
63-
code: [
64-
'var Hello = createReactClass({',
65-
' displayName: \'Hello\',',
66-
' render: function() {',
67-
' return <div></div>',
68-
' }',
69-
'});'
70-
].join('\n')
59+
code: `
60+
var Hello = createReactClass({
61+
displayName: 'Hello',
62+
render: function() {
63+
return <div></div>
64+
}
65+
});
66+
`
7167
}, {
72-
// Stateless function
73-
code: [
74-
'function Hello() {',
75-
' return <div></div>;',
76-
'}'
77-
].join('\n')
68+
code: `
69+
function Hello() {
70+
return <div></div>;
71+
}
72+
`
7873
}, {
79-
// Stateless arrow function
80-
code: [
81-
'var Hello = () => (',
82-
' <div></div>',
83-
');'
84-
].join('\n'),
74+
code: `
75+
var Hello = () => (
76+
<div></div>
77+
);
78+
`,
8579
parser: 'babel-eslint'
8680
}, {
87-
// Return in a switch...case
88-
code: [
89-
'var Hello = createReactClass({',
90-
' render: function() {',
91-
' switch (this.props.name) {',
92-
' case \'Foo\':',
93-
' return <div>Hello Foo</div>;',
94-
' default:',
95-
' return <div>Hello {this.props.name}</div>;',
96-
' }',
97-
' }',
98-
'});'
99-
].join('\n')
81+
code: `
82+
var Hello = createReactClass({
83+
render: function() {
84+
switch (this.props.name) {
85+
case 'Foo':
86+
return <div>Hello Foo</div>;
87+
default:
88+
return <div>Hello {this.props.name}</div>;
89+
}
90+
}
91+
});
92+
`
10093
}, {
101-
// Return in a if...else
102-
code: [
103-
'var Hello = createReactClass({',
104-
' render: function() {',
105-
' if (this.props.name === \'Foo\') {',
106-
' return <div>Hello Foo</div>;',
107-
' } else {',
108-
' return <div>Hello {this.props.name}</div>;',
109-
' }',
110-
' }',
111-
'});'
112-
].join('\n')
94+
code: `
95+
var Hello = createReactClass({
96+
render: function() {
97+
if (this.props.name === 'Foo') {
98+
return <div>Hello Foo</div>;
99+
} else {
100+
return <div>Hello {this.props.name}</div>;
101+
}
102+
}
103+
});
104+
`
113105
}, {
114-
// Not a React component
115-
code: [
116-
'class Hello {',
117-
' render() {}',
118-
'}'
119-
].join('\n')
106+
code: `
107+
class Hello {
108+
render() {}
109+
}
110+
`
120111
}, {
121112
// ES6 class without a render method
122113
code: 'class Hello extends React.Component {}'
123114
}, {
124115
// ES5 class without a render method
125116
code: 'var Hello = createReactClass({});'
126117
}, {
127-
// ES5 class with an imported render method
128-
code: [
129-
'var render = require(\'./render\');',
130-
'var Hello = createReactClass({',
131-
' render',
132-
'});'
133-
].join('\n')
118+
code: `
119+
var render = require('./render');
120+
var Hello = createReactClass({
121+
render
122+
});
123+
`
134124
}, {
135-
// Invalid render method (but accepted by Babel)
136-
code: [
137-
'class Foo extends Component {',
138-
' render',
139-
'}'
140-
].join('\n'),
125+
code: `
126+
class Foo extends Component {
127+
render
128+
}
129+
`,
141130
parser: 'babel-eslint'
142131
}],
143132

144133
invalid: [{
145-
// Missing return in ES5 class
146-
code: [
147-
'var Hello = createReactClass({',
148-
' displayName: \'Hello\',',
149-
' render: function() {}',
150-
'});'
151-
].join('\n'),
134+
code: `
135+
var Hello = createReactClass({
136+
displayName: 'Hello',
137+
render: function() {}
138+
});
139+
`,
152140
errors: [{
153141
message: 'Your render method should have return statement'
154142
}]
155143
}, {
156-
// Missing return in ES6 class
157-
code: [
158-
'class Hello extends React.Component {',
159-
' render() {} ',
160-
'}'
161-
].join('\n'),
144+
code: `
145+
class Hello extends React.Component {
146+
render() {}
147+
}
148+
`,
162149
errors: [{
163150
message: 'Your render method should have return statement'
164151
}]
165152
}, {
166-
// Missing return (but one is present in a sub-function)
167-
code: [
168-
'class Hello extends React.Component {',
169-
' render() {',
170-
' const names = this.props.names.map(function(name) {',
171-
' return <div>{name}</div>',
172-
' });',
173-
' } ',
174-
'}'
175-
].join('\n'),
153+
code: `
154+
class Hello extends React.Component {
155+
render() {
156+
const names = this.props.names.map(function(name) {
157+
return <div>{name}</div>
158+
});
159+
}
160+
}
161+
`,
176162
errors: [{
177163
message: 'Your render method should have return statement'
178164
}]
179165
}, {
180-
// Missing return ES6 class render property
181-
code: [
182-
'class Hello extends React.Component {',
183-
' render = () => {',
184-
' <div>Hello {this.props.name}</div>',
185-
' }',
186-
'}'
187-
].join('\n'),
166+
code: `
167+
class Hello extends React.Component {
168+
render = () => {
169+
<div>Hello {this.props.name}</div>
170+
}
171+
}
172+
`,
188173
parser: 'babel-eslint',
189174
errors: [{
190175
message: 'Your render method should have return statement'

0 commit comments

Comments
 (0)