Skip to content

Commit a0056b3

Browse files
committed
Rewrite no-set-state tests with template literals
1 parent f18b857 commit a0056b3

File tree

1 file changed

+78
-78
lines changed

1 file changed

+78
-78
lines changed

tests/lib/rules/no-set-state.js

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -28,106 +28,106 @@ const ruleTester = new RuleTester({parserOptions});
2828
ruleTester.run('no-set-state', rule, {
2929

3030
valid: [{
31-
code: [
32-
'var Hello = function() {',
33-
' this.setState({})',
34-
'};'
35-
].join('\n')
31+
code: `
32+
var Hello = function() {
33+
this.setState({})
34+
};
35+
`
3636
}, {
37-
code: [
38-
'var Hello = createReactClass({',
39-
' render: function() {',
40-
' return <div>Hello {this.props.name}</div>;',
41-
' }',
42-
'});'
43-
].join('\n')
37+
code: `
38+
var Hello = createReactClass({
39+
render: function() {
40+
return <div>Hello {this.props.name}</div>;
41+
}
42+
});
43+
`
4444
}, {
45-
code: [
46-
'var Hello = createReactClass({',
47-
' componentDidUpdate: function() {',
48-
' someNonMemberFunction(arg);',
49-
' this.someHandler = this.setState;',
50-
' },',
51-
' render: function() {',
52-
' return <div>Hello {this.props.name}</div>;',
53-
' }',
54-
'});'
55-
].join('\n')
45+
code: `
46+
var Hello = createReactClass({
47+
componentDidUpdate: function() {
48+
someNonMemberFunction(arg);
49+
this.someHandler = this.setState;
50+
},
51+
render: function() {
52+
return <div>Hello {this.props.name}</div>;
53+
}
54+
});
55+
`
5656
}],
5757

5858
invalid: [{
59-
code: [
60-
'var Hello = createReactClass({',
61-
' componentDidUpdate: function() {',
62-
' this.setState({',
63-
' name: this.props.name.toUpperCase()',
64-
' });',
65-
' },',
66-
' render: function() {',
67-
' return <div>Hello {this.state.name}</div>;',
68-
' }',
69-
'});'
70-
].join('\n'),
59+
code: `
60+
var Hello = createReactClass({
61+
componentDidUpdate: function() {
62+
this.setState({
63+
name: this.props.name.toUpperCase()
64+
});
65+
},
66+
render: function() {
67+
return <div>Hello {this.state.name}</div>;
68+
}
69+
});
70+
`,
7171
errors: [{
7272
message: 'Do not use setState'
7373
}]
7474
}, {
75-
code: [
76-
'var Hello = createReactClass({',
77-
' someMethod: function() {',
78-
' this.setState({',
79-
' name: this.props.name.toUpperCase()',
80-
' });',
81-
' },',
82-
' render: function() {',
83-
' return <div onClick={this.someMethod.bind(this)}>Hello {this.state.name}</div>;',
84-
' }',
85-
'});'
86-
].join('\n'),
75+
code: `
76+
var Hello = createReactClass({
77+
someMethod: function() {
78+
this.setState({
79+
name: this.props.name.toUpperCase()
80+
});
81+
},
82+
render: function() {
83+
return <div onClick={this.someMethod.bind(this)}>Hello {this.state.name}</div>;
84+
}
85+
});
86+
`,
8787
errors: [{
8888
message: 'Do not use setState'
8989
}]
9090
}, {
91-
code: [
92-
'class Hello extends React.Component {',
93-
' someMethod() {',
94-
' this.setState({',
95-
' name: this.props.name.toUpperCase()',
96-
' });',
97-
' }',
98-
' render() {',
99-
' return <div onClick={this.someMethod.bind(this)}>Hello {this.state.name}</div>;',
100-
' }',
101-
'};'
102-
].join('\n'),
91+
code: `
92+
class Hello extends React.Component {
93+
someMethod() {
94+
this.setState({
95+
name: this.props.name.toUpperCase()
96+
});
97+
}
98+
render() {
99+
return <div onClick={this.someMethod.bind(this)}>Hello {this.state.name}</div>;
100+
}
101+
};
102+
`,
103103
errors: [{
104104
message: 'Do not use setState'
105105
}]
106106
}, {
107-
code: [
108-
'class Hello extends React.Component {',
109-
' someMethod = () => {',
110-
' this.setState({',
111-
' name: this.props.name.toUpperCase()',
112-
' });',
113-
' }',
114-
' render() {',
115-
' return <div onClick={this.someMethod.bind(this)}>Hello {this.state.name}</div>;',
116-
' }',
117-
'};'
118-
].join('\n'),
107+
code: `
108+
class Hello extends React.Component {
109+
someMethod = () => {
110+
this.setState({
111+
name: this.props.name.toUpperCase()
112+
});
113+
}
114+
render() {
115+
return <div onClick={this.someMethod.bind(this)}>Hello {this.state.name}</div>;
116+
}
117+
};
118+
`,
119119
parser: 'babel-eslint',
120120
errors: [{
121121
message: 'Do not use setState'
122122
}]
123123
}, {
124-
code: [
125-
'class Hello extends React.Component {',
126-
' render() {',
127-
' return <div onMouseEnter={() => this.setState({dropdownIndex: index})} />;',
128-
' }',
129-
'};'
130-
].join('\n'),
124+
code: `
125+
class Hello extends React.Component {
126+
render() {
127+
return <div onMouseEnter={() => this.setState({dropdownIndex: index})} />;
128+
}
129+
};
130+
`,
131131
parser: 'babel-eslint',
132132
errors: [{
133133
message: 'Do not use setState'

0 commit comments

Comments
 (0)