Skip to content

Commit 8681c92

Browse files
committed
Rewrite require-optimization tests with template literals
1 parent d5d5e34 commit 8681c92

File tree

1 file changed

+110
-115
lines changed

1 file changed

+110
-115
lines changed

tests/lib/rules/require-optimization.js

Lines changed: 110 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -21,168 +21,163 @@ const MESSAGE = 'Component is not optimized. Please add a shouldComponentUpdate
2121
const ruleTester = new RuleTester({parserOptions});
2222
ruleTester.run('react-require-optimization', rule, {
2323
valid: [{
24-
code: [
25-
'class A {}'
26-
].join('\n')
27-
}, {
28-
code: [
29-
'import React from "react";' +
30-
'class YourComponent extends React.Component {' +
31-
'shouldComponentUpdate () {}' +
32-
'}'
33-
].join('\n')
34-
}, {
35-
code: [
36-
'import React, {Component} from "react";' +
37-
'class YourComponent extends Component {' +
38-
'shouldComponentUpdate () {}' +
39-
'}'
40-
].join('\n')
41-
}, {
42-
code: [
43-
'import React, {Component} from "react";',
44-
'@reactMixin.decorate(PureRenderMixin)',
45-
'class YourComponent extends Component {',
46-
' componetnDidMount () {}',
47-
' render() {}',
48-
'}'
49-
].join('\n'),
24+
code: `
25+
class A {}
26+
`
27+
}, {
28+
code: `
29+
import React from "react";
30+
class YourComponent extends React.Component {
31+
shouldComponentUpdate () {}
32+
}
33+
`
34+
}, {
35+
code: `
36+
import React, {Component} from "react";
37+
class YourComponent extends Component {
38+
shouldComponentUpdate () {}
39+
}
40+
`
41+
}, {
42+
code: `
43+
import React, {Component} from "react";
44+
@reactMixin.decorate(PureRenderMixin)
45+
class YourComponent extends Component {
46+
componetnDidMount () {}
47+
render() {}
48+
}
49+
`,
5050
parser: 'babel-eslint'
5151
}, {
52-
code: [
53-
'import React from "react";' +
54-
'createReactClass({' +
55-
'shouldComponentUpdate: function () {}' +
56-
'})'
57-
].join('\n')
58-
}, {
59-
code: [
60-
'import React from "react";' +
61-
'createReactClass({' +
62-
'mixins: [PureRenderMixin]' +
63-
'})'
64-
].join('\n')
65-
}, {
66-
code: [
67-
'@reactMixin.decorate(PureRenderMixin)',
68-
'class DecoratedComponent extends Component {' +
69-
'}'
70-
].join('\n'),
52+
code: `
53+
import React from "react";
54+
createReactClass({
55+
shouldComponentUpdate: function () {}
56+
})
57+
`
58+
}, {
59+
code: `
60+
import React from "react";
61+
createReactClass({
62+
mixins: [PureRenderMixin]
63+
})
64+
`
65+
}, {
66+
code: `
67+
@reactMixin.decorate(PureRenderMixin)
68+
class DecoratedComponent extends Component {}
69+
`,
7170
parser: 'babel-eslint'
7271
}, {
73-
code: [
74-
'const FunctionalComponent = function (props) {' +
75-
'return <div />;' +
76-
'}'
77-
].join('\n'),
72+
code: `
73+
const FunctionalComponent = function (props) {
74+
return <div />;
75+
}
76+
`,
7877
parser: 'babel-eslint'
7978
}, {
80-
code: [
81-
'function FunctionalComponent(props) {' +
82-
'return <div />;' +
83-
'}'
84-
].join('\n'),
79+
code: `
80+
function FunctionalComponent(props) {
81+
return <div />;
82+
}
83+
`,
8584
parser: 'babel-eslint'
8685
}, {
87-
code: [
88-
'const FunctionalComponent = (props) => {' +
89-
'return <div />;' +
90-
'}'
91-
].join('\n'),
86+
code: `
87+
const FunctionalComponent = (props) => {
88+
return <div />;
89+
}
90+
`,
9291
parser: 'babel-eslint'
9392
}, {
94-
code: [
95-
'@bar',
96-
'@pureRender',
97-
'@foo',
98-
'class DecoratedComponent extends Component {' +
99-
'}'
100-
].join('\n'),
93+
code: `
94+
@bar
95+
@pureRender
96+
@foo
97+
class DecoratedComponent extends Component {}
98+
`,
10199
parser: 'babel-eslint',
102100
options: [{allowDecorators: ['renderPure', 'pureRender']}]
103101
}, {
104-
code: [
105-
'import React from "react";' +
106-
'class YourComponent extends React.PureComponent {}'
107-
].join('\n'),
102+
code: `
103+
import React from "react";
104+
class YourComponent extends React.PureComponent {}
105+
`,
108106
parser: 'babel-eslint',
109107
options: [{allowDecorators: ['renderPure', 'pureRender']}]
110108
}, {
111-
code: [
112-
'import React, {PureComponent} from "react";' +
113-
'class YourComponent extends PureComponent {}'
114-
].join('\n'),
109+
code: `
110+
import React, {PureComponent} from "react";
111+
class YourComponent extends PureComponent {}
112+
`,
115113
parser: 'babel-eslint',
116114
options: [{allowDecorators: ['renderPure', 'pureRender']}]
117115
}],
118116

119117
invalid: [{
120-
code: [
121-
'import React from "react";' +
122-
'class YourComponent extends React.Component {}'
123-
].join('\n'),
118+
code: `
119+
import React from "react";
120+
class YourComponent extends React.Component {}
121+
`,
124122
errors: [{
125123
message: MESSAGE
126124
}]
127125
}, {
128-
code: [
129-
'import React from "react";',
130-
'class YourComponent extends React.Component {',
131-
' handleClick() {}',
132-
' render() {',
133-
' return <div onClick={this.handleClick}>123</div>',
134-
' }',
135-
'}'
136-
].join('\n'),
126+
code: `
127+
import React from "react";
128+
class YourComponent extends React.Component {
129+
handleClick() {}
130+
render() {
131+
return <div onClick={this.handleClick}>123</div>
132+
}
133+
}
134+
`,
137135
parser: 'babel-eslint',
138136
errors: [{
139137
message: MESSAGE
140138
}]
141139
}, {
142-
code: [
143-
'import React, {Component} from "react";' +
144-
'class YourComponent extends Component {}'
145-
].join('\n'),
140+
code: `
141+
import React, {Component} from "react";
142+
class YourComponent extends Component {}
143+
`,
146144
errors: [{
147145
message: MESSAGE
148146
}]
149147
}, {
150-
code: [
151-
'import React from "react";' +
152-
'createReactClass({' +
153-
'})'
154-
].join('\n'),
148+
code: `
149+
import React from "react";
150+
createReactClass({})
151+
`,
155152
errors: [{
156153
message: MESSAGE
157154
}]
158155
}, {
159-
code: [
160-
'import React from "react";' +
161-
'createReactClass({' +
162-
'mixins: [RandomMixin]' +
163-
'})'
164-
].join('\n'),
156+
code: `
157+
import React from "react";
158+
createReactClass({
159+
mixins: [RandomMixin]
160+
})
161+
`,
165162
errors: [{
166163
message: MESSAGE
167164
}]
168165
}, {
169-
code: [
170-
'@reactMixin.decorate(SomeOtherMixin)',
171-
'class DecoratedComponent extends Component {' +
172-
'}'
173-
].join('\n'),
166+
code: `
167+
@reactMixin.decorate(SomeOtherMixin)
168+
class DecoratedComponent extends Component {}
169+
`,
174170
errors: [{
175171
message: MESSAGE
176172
}],
177173
parser: 'babel-eslint'
178174
}, {
179-
code: [
180-
'@bar',
181-
'@pure',
182-
'@foo',
183-
'class DecoratedComponent extends Component {' +
184-
'}'
185-
].join('\n'),
175+
code: `
176+
@bar
177+
@pure
178+
@foo
179+
class DecoratedComponent extends Component {}
180+
`,
186181
errors: [{
187182
message: MESSAGE
188183
}],

0 commit comments

Comments
 (0)