Enable linting for __tests__
Closes #3971. > After #3968, the next thing we should do is start linting our tests. > Historically we've ignored them due to lack of parser compatibility. > But that shouldn't be a problem anymore. We may want to integrate > https://www.npmjs.com/package/eslint-plugin-react to more aggressively > lint our JSX in tests. I understand this diff touches a lot of stuff, so I tried to keep it to a near-minimal set of changes to make eslint happy.
Benjamin Woodruff committed
May 29, 2015 at 10:52 UTC
21ca3f732fc1b4a182a58452bd2b8c30b9434c79
53 files changed
+366
-349
.eslintignore
-4
@@ -1,9 +1,5 @@
1
# We can probably lint these later but not important at this point
2
src/shared/vendor
3
-# eslint uses JSX* node types to determine if using JSX. esprima-fb still uses
4
-# XJS* nodes. When we fix that (https://github.com/facebook/esprima/pull/85) we
5
-# can enable linting the tests and fix those errors.
6
-src/**/__tests__/**
3
# This should be enabled but that folder has too much in it that doesn't belong
4
src/test
5
test/the-files-to-test.generated.js
.eslintrc
+22
-1
@@ -1,12 +1,27 @@
1
---
2
parser: babel-eslint
3
4
+plugins:
5
+ - react
6
+
7
env:
8
browser: true
9
node: true
10
11
globals:
12
__DEV__: true
13
+ # Jest / Jasmine
14
+ describe: false
15
+ xdescribe: false
16
+ beforeEach: false
17
+ afterEach: false
18
+ it: false
19
+ xit: false
20
+ jest: false
21
+ pit: false
22
+ expect: false
23
+ spyOn: false
24
+ jasmine: false
25
26
rules:
27
# ERRORS
@@ -26,7 +41,7 @@ rules:
41
dot-location: [2, property]
42
consistent-return: 2
43
no-unused-vars: [2, args: none]
29
- quotes: [2, single]
44
+ quotes: [2, single, avoid-escape]
45
no-shadow: 2
46
no-multi-spaces: 2
47
@@ -50,7 +65,13 @@ rules:
65
key-spacing: 0
66
# It's nice to be able to leave catch blocks empty
67
no-empty: 0
68
+ # It makes code more readable to make this explicit sometimes
69
+ no-undef-init: 0
70
71
# BROKEN. We'd like to turn these back on.
72
# causes a ton of noise, eslint is too picky?
73
block-scoped-var: 0
74
+
75
+ # JSX
76
+ react/jsx-uses-react: 2
77
+ react/jsx-quotes: [2, "double"]
npm-react/addons.js
+2
-2
@@ -1,8 +1,8 @@
1
var warning = require('./lib/warning');
2
warning(
3
false,
4
- 'require("react/addons") is deprecated. ' +
5
- 'Access using require("react/addons/{addon}") instead.'
4
+ "require('react/addons') is deprecated. " +
5
+ "Access using require('react/addons/{addon}') instead."
6
);
7
8
module.exports = require('./lib/ReactWithAddons');
package.json
+1
@@ -40,6 +40,7 @@
40
"envify": "^3.0.0",
41
"es5-shim": "^4.0.0",
42
"eslint": "^0.21.2",
43
+ "eslint-plugin-react": "^2.3.0",
44
"grunt": "~0.4.2",
45
"grunt-cli": "^0.1.13",
46
"grunt-compare-size": "~0.4.0",
src/addons/__tests__/ReactComponentWithPureRenderMixin-test.js
+5
-5
@@ -50,20 +50,20 @@ describe('ReactComponentWithPureRenderMixin', function() {
50
getInitialState: function() {
51
return {
52
cut: false,
53
- slices: 1,
53
+ slices: 1
54
};
55
},
56
57
cut: function() {
58
this.setState({
59
cut: true,
60
- slices: 10,
60
+ slices: 10
61
});
62
},
63
64
eatSlice: function() {
65
this.setState({
66
- slices: this.state.slices - 1,
66
+ slices: this.state.slices - 1
67
});
68
},
69
@@ -101,7 +101,7 @@ describe('ReactComponentWithPureRenderMixin', function() {
101
function getInitialState() {
102
return {
103
foo: [1, 2, 3],
104
- bar: {a: 4, b: 5, c: 6},
104
+ bar: {a: 4, b: 5, c: 6}
105
};
106
}
107
@@ -127,7 +127,7 @@ describe('ReactComponentWithPureRenderMixin', function() {
127
// Do not re-render if state is equal
128
var settings = {
129
foo: initialSettings.foo,
130
- bar: initialSettings.bar,
130
+ bar: initialSettings.bar
131
};
132
instance.setState(settings);
133
expect(renderCalls).toBe(1);
src/addons/__tests__/ReactFragment-test.js
+3
-3
@@ -27,7 +27,7 @@ describe('ReactFragment', function() {
27
x: <span />,
28
y: <span />
29
};
30
- <div>{children}</div>;
30
+ void <div>{children}</div>;
31
expect(console.error.calls.length).toBe(1);
32
expect(console.error.calls[0].args[0]).toContain(
33
'Any use of a keyed object'
@@ -37,7 +37,7 @@ describe('ReactFragment', function() {
37
x: <span />,
38
y: <span />
39
};
40
- <div>{sameChildren}</div>;
40
+ void <div>{sameChildren}</div>;
41
expect(console.error.calls.length).toBe(1);
42
});
43
@@ -65,7 +65,7 @@ describe('ReactFragment', function() {
65
y: <span />
66
};
67
var frag = ReactFragment.create(children);
68
- frag.x;
68
+ void frag.x;
69
frag.y = 10;
70
expect(console.error.calls.length).toBe(1);
71
expect(console.error.calls[0].args[0]).toContain(
src/addons/__tests__/renderSubtreeIntoContainer.js
+2
-2
@@ -33,7 +33,7 @@ describe('renderSubtreeIntoContainer', function() {
33
34
var Parent = React.createClass({
35
childContextTypes: {
36
- foo: React.PropTypes.string.isRequired,
36
+ foo: React.PropTypes.string.isRequired
37
},
38
39
getChildContext: function() {
@@ -72,7 +72,7 @@ describe('renderSubtreeIntoContainer', function() {
72
73
var Parent = React.createClass({
74
childContextTypes: {
75
- foo: React.PropTypes.string.isRequired,
75
+ foo: React.PropTypes.string.isRequired
76
},
77
78
getChildContext: function() {
src/addons/__tests__/update-test.js
+1
-1
@@ -72,7 +72,7 @@ describe('update', function() {
72
});
73
74
it('should support apply', function() {
75
- expect(update(2, {$apply: function(x) { return x * 2; }})).toEqual(4);
75
+ expect(update(2, {$apply: (x) => x * 2})).toEqual(4);
76
expect(update.bind(null, 2, {$apply: 123})).toThrow(
77
'Invariant Violation: update(): expected spec of $apply to be a ' +
78
'function; got 123.'
src/addons/link/__tests__/LinkedStateMixin-test.js
-2
@@ -16,13 +16,11 @@
16
describe('LinkedStateMixin', function() {
17
var LinkedStateMixin;
18
var React;
19
- var ReactLink;
19
var ReactTestUtils;
20
21
beforeEach(function() {
22
LinkedStateMixin = require('LinkedStateMixin');
23
React = require('React');
25
- ReactLink = require('ReactLink');
24
ReactTestUtils = require('ReactTestUtils');
25
});
26
src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js
+1
-3
@@ -13,7 +13,6 @@
13
14
var React;
15
var ReactCSSTransitionGroup;
16
-var mocks;
16
17
// Most of the real functionality is covered in other unit tests, this just
18
// makes sure we're wired up correctly.
@@ -23,7 +22,6 @@ describe('ReactCSSTransitionGroup', function() {
22
beforeEach(function() {
23
React = require('React');
24
ReactCSSTransitionGroup = require('ReactCSSTransitionGroup');
26
- mocks = require('mocks');
25
26
container = document.createElement('div');
27
spyOn(console, 'error');
@@ -52,7 +50,7 @@ describe('ReactCSSTransitionGroup', function() {
50
51
// For some reason jst is adding extra setTimeout()s and grunt test isn't,
52
// so we need to do this disgusting hack.
55
- for (var i = 0 ; i < setTimeout.mock.calls.length; i++) {
53
+ for (var i = 0; i < setTimeout.mock.calls.length; i++) {
54
if (setTimeout.mock.calls[i][1] === 5000) {
55
setTimeout.mock.calls[i][0]();
56
break;
src/addons/transitions/__tests__/ReactTransitionGroup-test.js
+11
-13
@@ -13,7 +13,6 @@
13
14
var React;
15
var ReactTransitionGroup;
16
-var mocks;
16
17
// Most of the real functionality is covered in other unit tests, this just
18
// makes sure we're wired up correctly.
@@ -23,7 +22,6 @@ describe('ReactTransitionGroup', function() {
22
beforeEach(function() {
23
React = require('React');
24
ReactTransitionGroup = require('ReactTransitionGroup');
26
- mocks = require('mocks');
25
26
container = document.createElement('div');
27
});
@@ -94,15 +92,15 @@ describe('ReactTransitionGroup', function() {
92
93
it('should handle enter/leave/enter/leave correctly', function() {
94
var log = [];
97
- var cb;
95
+ var willEnterCb;
96
97
var Child = React.createClass({
98
componentDidMount: function() {
99
log.push('didMount');
100
},
103
- componentWillEnter: function(_cb) {
101
+ componentWillEnter: function(cb) {
102
log.push('willEnter');
105
- cb = _cb;
103
+ willEnterCb = cb;
104
},
105
componentDidEnter: function() {
106
log.push('didEnter');
@@ -139,12 +137,13 @@ describe('ReactTransitionGroup', function() {
137
expect(log).toEqual(['didMount']);
138
instance.setState({count: 2});
139
expect(log).toEqual(['didMount', 'didMount', 'willEnter']);
142
- for (var i = 0; i < 5; i++) {
140
+ for (var k = 0; k < 5; k++) {
141
instance.setState({count: 2});
142
expect(log).toEqual(['didMount', 'didMount', 'willEnter']);
143
instance.setState({count: 1});
144
}
147
- cb();
145
+ // other animations are blocked until willEnterCb is called
146
+ willEnterCb();
147
expect(log).toEqual([
148
'didMount', 'didMount', 'willEnter',
149
'didEnter', 'willLeave', 'didLeave', 'willUnmount'
@@ -153,15 +152,15 @@ describe('ReactTransitionGroup', function() {
152
153
it('should handle enter/leave/enter correctly', function() {
154
var log = [];
156
- var cb;
155
+ var willEnterCb;
156
157
var Child = React.createClass({
158
componentDidMount: function() {
159
log.push('didMount');
160
},
162
- componentWillEnter: function(_cb) {
161
+ componentWillEnter: function(cb) {
162
log.push('willEnter');
164
- cb = _cb;
163
+ willEnterCb = cb;
164
},
165
componentDidEnter: function() {
166
log.push('didEnter');
@@ -198,12 +197,12 @@ describe('ReactTransitionGroup', function() {
197
expect(log).toEqual(['didMount']);
198
instance.setState({count: 2});
199
expect(log).toEqual(['didMount', 'didMount', 'willEnter']);
201
- for (var i = 0; i < 5; i++) {
200
+ for (var k = 0; k < 5; k++) {
201
instance.setState({count: 1});
202
expect(log).toEqual(['didMount', 'didMount', 'willEnter']);
203
instance.setState({count: 2});
204
}
206
- cb();
205
+ willEnterCb();
206
expect(log).toEqual([
207
'didMount', 'didMount', 'willEnter', 'didEnter'
208
]);
@@ -211,7 +210,6 @@ describe('ReactTransitionGroup', function() {
210
211
it('should handle entering/leaving several elements at once', function() {
212
var log = [];
214
- var cb;
213
214
var Child = React.createClass({
215
componentDidMount: function() {
src/isomorphic/children/__tests__/ReactChildren-test.js
+8
-10
@@ -22,10 +22,6 @@ describe('ReactChildren', function() {
22
ReactFragment = require('ReactFragment');
23
});
24
25
- function frag(obj) {
26
- return ReactFragment.create(obj);
27
- }
28
-
25
function nthChild(mappedChildren, n) {
26
var result = null;
27
ReactChildren.forEach(mappedChildren, function(child, index) {
@@ -227,7 +223,7 @@ describe('ReactChildren', function() {
223
224
var instance = (
225
<div>{
230
- [frag({
226
+ [ReactFragment.create({
227
firstHalfKey: [zero, one, two],
228
secondHalfKey: [three, four],
229
keyFive: five
@@ -345,7 +341,9 @@ describe('ReactChildren', function() {
341
var zero = <div key="something"/>;
342
var one = <span key="something" />;
343
348
- var mapFn = function(component) { return component; };
344
+ var mapFn = function(component) {
345
+ return component;
346
+ };
347
var instance = (
348
<div>{zero}{one}</div>
349
);
@@ -410,7 +408,7 @@ describe('ReactChildren', function() {
408
409
var instance = (
410
<div>{
413
- [frag({
411
+ [ReactFragment.create({
412
firstHalfKey: [zero, one, two],
413
secondHalfKey: [three, four],
414
keyFive: five
@@ -438,7 +436,7 @@ describe('ReactChildren', function() {
436
return c;
437
});
438
for (var key in frag) {
441
- frag[key];
439
+ void frag[key];
440
break;
441
}
442
expect(console.error.calls.length).toBe(1);
@@ -447,8 +445,8 @@ describe('ReactChildren', function() {
445
var frag2 = ReactChildren.map([child, child], function(c) {
446
return c;
447
});
450
- for (var key in frag2) {
451
- frag2[key] = 123;
448
+ for (var key2 in frag2) {
449
+ frag2[key2] = 123;
450
break;
451
}
452
expect(console.error.calls.length).toBe(2);
src/isomorphic/classic/__tests__/ReactContextValidator-test.js
+2
-4
@@ -21,7 +21,6 @@ var React;
21
var ReactTestUtils;
22
23
var reactComponentExpect;
24
-var mocks;
24
25
describe('ReactContextValidator', function() {
26
beforeEach(function() {
@@ -30,7 +29,6 @@ describe('ReactContextValidator', function() {
29
React = require('React');
30
ReactTestUtils = require('ReactTestUtils');
31
reactComponentExpect = require('reactComponentExpect');
33
- mocks = require('mocks');
32
33
spyOn(console, 'error');
34
});
@@ -86,7 +84,7 @@ describe('ReactContextValidator', function() {
84
getChildContext: function() {
85
return {
86
foo: this.props.foo,
89
- bar: "bar"
87
+ bar: 'bar'
88
};
89
},
90
@@ -125,7 +123,7 @@ describe('ReactContextValidator', function() {
123
124
var instance = <Parent foo="abc" />;
125
instance = ReactTestUtils.renderIntoDocument(instance);
128
- instance.replaceProps({foo: "def"});
126
+ instance.replaceProps({foo: 'def'});
127
expect(actualComponentWillReceiveProps).toEqual({foo: 'def'});
128
expect(actualShouldComponentUpdate).toEqual({foo: 'def'});
129
expect(actualComponentWillUpdate).toEqual({foo: 'def'});
src/isomorphic/classic/class/__tests__/ReactBind-test.js
+3
-3
@@ -36,7 +36,7 @@ describe('autobinding', function() {
36
// auto binding only occurs on top level functions in class defs.
37
badIdeas: {
38
badBind: function() {
39
- this.state.something;
39
+ void this.state.something;
40
}
41
},
42
@@ -131,7 +131,7 @@ describe('autobinding', function() {
131
}
132
});
133
134
- ReactTestUtils.renderIntoDocument(<TestBindComponent />)
134
+ ReactTestUtils.renderIntoDocument(<TestBindComponent />);
135
136
expect(console.error.argsForCall.length).toBe(1);
137
expect(console.error.argsForCall[0][0]).toBe(
@@ -159,7 +159,7 @@ describe('autobinding', function() {
159
}
160
});
161
162
- ReactTestUtils.renderIntoDocument(<TestBindComponent />)
162
+ ReactTestUtils.renderIntoDocument(<TestBindComponent />);
163
164
expect(console.error.argsForCall.length).toBe(0);
165
});
src/isomorphic/classic/class/__tests__/ReactClass-test.js
+2
-3
@@ -175,7 +175,8 @@ describe('ReactClass-spec', function() {
175
'because the function is expected to return a value.'
176
);
177
178
- var NamedComponent = React.createClass({
178
+ React.createClass({
179
+ displayName: 'NamedComponent',
180
componentShouldUpdate: function() {
181
return false;
182
},
@@ -189,8 +190,6 @@ describe('ReactClass-spec', function() {
190
'mean shouldComponentUpdate()? The name is phrased as a question ' +
191
'because the function is expected to return a value.'
192
);
192
-
193
- <NamedComponent />; // Shut up lint
193
});
194
195
it('should throw if a reserved property is in statics', function() {
src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js
+29
-25
@@ -15,7 +15,6 @@ var mocks = require('mocks');
15
16
var React;
17
var ReactTestUtils;
18
-var reactComponentExpect;
18
19
var TestComponent;
20
var TestComponentWithPropTypes;
@@ -28,7 +27,6 @@ describe('ReactClass-mixin', function() {
27
beforeEach(function() {
28
React = require('React');
29
ReactTestUtils = require('ReactTestUtils');
31
- reactComponentExpect = require('reactComponentExpect');
30
mixinPropValidator = mocks.getMockFunction();
31
componentPropValidator = mocks.getMockFunction();
32
@@ -288,18 +286,22 @@ describe('ReactClass-mixin', function() {
286
);
287
});
288
291
- it("should throw if mixins override functions in statics", function() {
289
+ it('should throw if mixins override functions in statics', function() {
290
expect(function() {
291
var Mixin = {
292
statics: {
295
- abc: function() { console.log('foo'); }
293
+ abc: function() {
294
+ console.log('foo');
295
+ }
296
}
297
};
298
React.createClass({
299
mixins: [Mixin],
300
301
statics: {
302
- abc: function() { console.log('bar'); }
302
+ abc: function() {
303
+ console.log('bar');
304
+ }
305
},
306
307
render: function() {
@@ -313,7 +315,7 @@ describe('ReactClass-mixin', function() {
315
);
316
});
317
316
- it("should throw if the mixin is a React component", function() {
318
+ it('should throw if the mixin is a React component', function() {
319
expect(function() {
320
React.createClass({
321
mixins: [<div />],
@@ -328,7 +330,7 @@ describe('ReactClass-mixin', function() {
330
);
331
});
332
331
- it("should throw if the mixin is a React component class", function() {
333
+ it('should throw if the mixin is a React component class', function() {
334
expect(function() {
335
var Component = React.createClass({
336
render: function() {
@@ -351,7 +353,9 @@ describe('ReactClass-mixin', function() {
353
354
it('should have bound the mixin methods to the component', function() {
355
var mixin = {
354
- mixinFunc: function() {return this;}
356
+ mixinFunc: function() {
357
+ return this;
358
+ }
359
};
360
361
var Component = React.createClass({
@@ -368,24 +372,24 @@ describe('ReactClass-mixin', function() {
372
});
373
374
it('should include the mixin keys in even if their values are falsy',
371
- function() {
372
- var mixin = {
373
- keyWithNullValue: null,
374
- randomCounter: 0
375
- };
375
+ function() {
376
+ var mixin = {
377
+ keyWithNullValue: null,
378
+ randomCounter: 0
379
+ };
380
377
- var Component = React.createClass({
378
- mixins: [mixin],
379
- componentDidMount: function() {
380
- expect(this.randomCounter).toBe(0);
381
- expect(this.keyWithNullValue).toBeNull();
382
- },
383
- render: function() {
384
- return <span />;
385
- }
386
- });
387
- var instance = <Component />;
388
- instance = ReactTestUtils.renderIntoDocument(instance);
381
+ var Component = React.createClass({
382
+ mixins: [mixin],
383
+ componentDidMount: function() {
384
+ expect(this.randomCounter).toBe(0);
385
+ expect(this.keyWithNullValue).toBeNull();
386
+ },
387
+ render: function() {
388
+ return <span />;
389
+ }
390
+ });
391
+ var instance = <Component />;
392
+ instance = ReactTestUtils.renderIntoDocument(instance);
393
});
394
395
it('should work with a null getInitialState return value and a mixin', () => {
src/isomorphic/classic/element/__tests__/ReactElement-test.js
+11
-13
@@ -14,8 +14,6 @@
14
// NOTE: We're explicitly not using JSX in this file. This is intended to test
15
// classic JS without JSX.
16
17
-var mocks;
18
-
17
var React;
18
var ReactTestUtils;
19
@@ -25,12 +23,12 @@ describe('ReactElement', function() {
23
beforeEach(function() {
24
require('mock-modules').dumpCache();
25
28
- mocks = require('mocks');
29
-
26
React = require('React');
27
ReactTestUtils = require('ReactTestUtils');
28
ComponentClass = React.createClass({
33
- render: function() { return React.createElement('div'); }
29
+ render: function() {
30
+ return React.createElement('div');
31
+ }
32
});
33
});
34
@@ -143,7 +141,7 @@ describe('ReactElement', function() {
141
it('allows static methods to be called using the type property', function() {
142
spyOn(console, 'error');
143
146
- var ComponentClass = React.createClass({
144
+ var StaticMethodComponentClass = React.createClass({
145
statics: {
146
someStaticMethod: function() {
147
return 'someReturnValue';
@@ -157,7 +155,7 @@ describe('ReactElement', function() {
155
}
156
});
157
160
- var element = React.createElement(ComponentClass);
158
+ var element = React.createElement(StaticMethodComponentClass);
159
expect(element.type.someStaticMethod()).toBe('someReturnValue');
160
expect(console.error.argsForCall.length).toBe(0);
161
});
@@ -177,7 +175,7 @@ describe('ReactElement', function() {
175
expect(React.isValidElement(null)).toEqual(false);
176
expect(React.isValidElement(true)).toEqual(false);
177
expect(React.isValidElement({})).toEqual(false);
180
- expect(React.isValidElement("string")).toEqual(false);
178
+ expect(React.isValidElement('string')).toEqual(false);
179
expect(React.isValidElement(React.DOM.div)).toEqual(false);
180
expect(React.isValidElement(Component)).toEqual(false);
181
});
@@ -193,8 +191,8 @@ describe('ReactElement', function() {
191
}
192
});
193
196
- expect(typeof Component.specialType).toBe("function");
197
- expect(typeof Component.specialType.isRequired).toBe("function");
194
+ expect(typeof Component.specialType).toBe('function');
195
+ expect(typeof Component.specialType.isRequired).toBe('function');
196
});
197
198
it('is indistinguishable from a plain object', function() {
@@ -285,7 +283,7 @@ describe('ReactElement', function() {
283
284
it('warns when adding a prop after element creation', function() {
285
spyOn(console, 'error');
288
- var el = document.createElement('div');
286
+ var container = document.createElement('div');
287
var Outer = React.createClass({
288
getDefaultProps: () => ({sound: 'meow'}),
289
render: function() {
@@ -299,7 +297,7 @@ describe('ReactElement', function() {
297
return el;
298
}
299
});
302
- var outer = React.render(<Outer />, el);
300
+ var outer = React.render(<Outer />, container);
301
expect(React.findDOMNode(outer).textContent).toBe('meow');
302
expect(React.findDOMNode(outer).className).toBe('quack');
303
@@ -315,7 +313,7 @@ describe('ReactElement', function() {
313
314
var newOuterEl = <Outer />;
315
newOuterEl.props.sound = 'oink';
318
- outer = React.render(newOuterEl, el);
316
+ outer = React.render(newOuterEl, container);
317
expect(React.findDOMNode(outer).textContent).toBe('oink');
318
expect(React.findDOMNode(outer).className).toBe('quack');
319
src/isomorphic/classic/element/__tests__/ReactElementClone-test.js
-2
@@ -13,8 +13,6 @@
13
14
require('mock-modules');
15
16
-var mocks = require('mocks');
17
-
16
var React;
17
var ReactTestUtils;
18
src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
+7
-4
@@ -28,7 +28,9 @@ describe('ReactElementValidator', function() {
28
ReactFragment = require('ReactFragment');
29
ReactTestUtils = require('ReactTestUtils');
30
ComponentClass = React.createClass({
31
- render: function() { return React.createElement('div'); }
31
+ render: function() {
32
+ return React.createElement('div');
33
+ }
34
});
35
});
36
@@ -213,7 +215,8 @@ describe('ReactElementValidator', function() {
215
);
216
});
217
216
- it('does not warn for numeric keys in entry iterables in rest args', function() {
218
+ it('does not warn for numeric keys in entry iterables in rest args',
219
+ function() {
220
spyOn(console, 'error');
221
var Component = React.createFactory(ComponentClass);
222
@@ -283,7 +286,7 @@ describe('ReactElementValidator', function() {
286
});
287
288
it('gives a helpful error when passing null, undefined, boolean, or number',
286
- () => {
289
+ function() {
290
spyOn(console, 'error');
291
React.createElement(undefined);
292
React.createElement(null);
@@ -315,7 +318,7 @@ describe('ReactElementValidator', function() {
318
});
319
320
it('includes the owner name when passing null, undefined, boolean, or number',
318
- () => {
321
+ function() {
322
spyOn(console, 'error');
323
var ParentComp = React.createClass({
324
render: function() {
src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
+40
-39
@@ -55,7 +55,7 @@ describe('ReactPropTypes', function() {
55
});
56
57
describe('Primitive Types', function() {
58
- it("should warn for invalid strings", function() {
58
+ it('should warn for invalid strings', function() {
59
typeCheckFail(
60
PropTypes.string,
61
[],
@@ -97,7 +97,7 @@ describe('ReactPropTypes', function() {
97
);
98
});
99
100
- it("should not warn for valid values", function() {
100
+ it('should not warn for valid values', function() {
101
typeCheckPass(PropTypes.array, []);
102
typeCheckPass(PropTypes.bool, false);
103
typeCheckPass(PropTypes.func, function() {});
@@ -108,12 +108,12 @@ describe('ReactPropTypes', function() {
108
typeCheckPass(PropTypes.object, /please/);
109
});
110
111
- it("should be implicitly optional and not warn without values", function() {
111
+ it('should be implicitly optional and not warn without values', function() {
112
typeCheckPass(PropTypes.string, null);
113
typeCheckPass(PropTypes.string, undefined);
114
});
115
116
- it("should warn for missing required values", function() {
116
+ it('should warn for missing required values', function() {
117
typeCheckFail(PropTypes.string.isRequired, null, requiredMessage);
118
typeCheckFail(PropTypes.string.isRequired, undefined, requiredMessage);
119
});
@@ -126,12 +126,12 @@ describe('ReactPropTypes', function() {
126
typeCheckPass(PropTypes.any, []);
127
});
128
129
- it("should be implicitly optional and not warn without values", function() {
129
+ it('should be implicitly optional and not warn without values', function() {
130
typeCheckPass(PropTypes.any, null);
131
typeCheckPass(PropTypes.any, undefined);
132
});
133
134
- it("should warn for missing required values", function() {
134
+ it('should warn for missing required values', function() {
135
typeCheckFail(PropTypes.any.isRequired, null, requiredMessage);
136
typeCheckFail(PropTypes.any.isRequired, undefined, requiredMessage);
137
});
@@ -203,12 +203,12 @@ describe('ReactPropTypes', function() {
203
typeCheckPass(PropTypes.arrayOf(PropTypes.number), []);
204
});
205
206
- it("should be implicitly optional and not warn without values", function() {
206
+ it('should be implicitly optional and not warn without values', function() {
207
typeCheckPass(PropTypes.arrayOf(PropTypes.number), null);
208
typeCheckPass(PropTypes.arrayOf(PropTypes.number), undefined);
209
});
210
211
- it("should warn for missing required values", function() {
211
+ it('should warn for missing required values', function() {
212
typeCheckFail(
213
PropTypes.arrayOf(PropTypes.number).isRequired,
214
null,
@@ -263,19 +263,19 @@ describe('ReactPropTypes', function() {
263
expect(console.error.argsForCall.length).toBe(1);
264
});
265
266
- it("should be implicitly optional and not warn without values", function() {
266
+ it('should be implicitly optional and not warn without values', function() {
267
typeCheckPass(PropTypes.element, null);
268
typeCheckPass(PropTypes.element, undefined);
269
});
270
271
- it("should warn for missing required values", function() {
271
+ it('should warn for missing required values', function() {
272
typeCheckFail(PropTypes.element.isRequired, null, requiredMessage);
273
typeCheckFail(PropTypes.element.isRequired, undefined, requiredMessage);
274
});
275
});
276
277
describe('Instance Types', function() {
278
- it("should warn for invalid instances", function() {
278
+ it('should warn for invalid instances', function() {
279
function Person() {}
280
var personName = Person.name || '<<anonymous>>';
281
var dateName = Date.name || '<<anonymous>>';
@@ -313,7 +313,7 @@ describe('ReactPropTypes', function() {
313
);
314
});
315
316
- it("should not warn for valid values", function() {
316
+ it('should not warn for valid values', function() {
317
function Person() {}
318
function Engineer() {}
319
Engineer.prototype = new Person();
@@ -325,12 +325,12 @@ describe('ReactPropTypes', function() {
325
typeCheckPass(PropTypes.instanceOf(RegExp), /please/);
326
});
327
328
- it("should be implicitly optional and not warn without values", function() {
328
+ it('should be implicitly optional and not warn without values', function() {
329
typeCheckPass(PropTypes.instanceOf(String), null);
330
typeCheckPass(PropTypes.instanceOf(String), undefined);
331
});
332
333
- it("should warn for missing required values", function() {
333
+ it('should warn for missing required values', function() {
334
typeCheckFail(
335
PropTypes.instanceOf(String).isRequired, null, requiredMessage
336
);
@@ -500,12 +500,12 @@ describe('ReactPropTypes', function() {
500
typeCheckPass(PropTypes.objectOf(PropTypes.number), {});
501
});
502
503
- it("should be implicitly optional and not warn without values", function() {
503
+ it('should be implicitly optional and not warn without values', function() {
504
typeCheckPass(PropTypes.objectOf(PropTypes.number), null);
505
typeCheckPass(PropTypes.objectOf(PropTypes.number), undefined);
506
});
507
508
- it("should warn for missing required values", function() {
508
+ it('should warn for missing required values', function() {
509
typeCheckFail(
510
PropTypes.objectOf(PropTypes.number).isRequired,
511
null,
@@ -520,7 +520,7 @@ describe('ReactPropTypes', function() {
520
});
521
522
describe('OneOf Types', function() {
523
- it("should fail for invalid argument", function() {
523
+ it('should fail for invalid argument', function() {
524
typeCheckFail(
525
PropTypes.oneOf('red', 'blue'),
526
'red',
@@ -528,7 +528,7 @@ describe('ReactPropTypes', function() {
528
);
529
});
530
531
- it("should warn for invalid strings", function() {
531
+ it('should warn for invalid strings', function() {
532
typeCheckFail(
533
PropTypes.oneOf(['red', 'blue']),
534
true,
@@ -555,17 +555,17 @@ describe('ReactPropTypes', function() {
555
);
556
});
557
558
- it("should not warn for valid values", function() {
558
+ it('should not warn for valid values', function() {
559
typeCheckPass(PropTypes.oneOf(['red', 'blue']), 'red');
560
typeCheckPass(PropTypes.oneOf(['red', 'blue']), 'blue');
561
});
562
563
- it("should be implicitly optional and not warn without values", function() {
563
+ it('should be implicitly optional and not warn without values', function() {
564
typeCheckPass(PropTypes.oneOf(['red', 'blue']), null);
565
typeCheckPass(PropTypes.oneOf(['red', 'blue']), undefined);
566
});
567
568
- it("should warn for missing required values", function() {
568
+ it('should warn for missing required values', function() {
569
typeCheckFail(
570
PropTypes.oneOf(['red', 'blue']).isRequired,
571
null,
@@ -580,7 +580,7 @@ describe('ReactPropTypes', function() {
580
});
581
582
describe('Union Types', function() {
583
- it("should fail for invalid argument", function() {
583
+ it('should fail for invalid argument', function() {
584
typeCheckFail(
585
PropTypes.oneOfType(PropTypes.string, PropTypes.number),
586
'red',
@@ -623,7 +623,7 @@ describe('ReactPropTypes', function() {
623
typeCheckPass(checker, {b: 1});
624
});
625
626
- it("should be implicitly optional and not warn without values", function() {
626
+ it('should be implicitly optional and not warn without values', function() {
627
typeCheckPass(
628
PropTypes.oneOfType([PropTypes.string, PropTypes.number]), null
629
);
@@ -632,7 +632,7 @@ describe('ReactPropTypes', function() {
632
);
633
});
634
635
- it("should warn for missing required values", function() {
635
+ it('should warn for missing required values', function() {
636
typeCheckFail(
637
PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
638
null,
@@ -647,7 +647,7 @@ describe('ReactPropTypes', function() {
647
});
648
649
describe('Shape Types', function() {
650
- it("should warn for non objects", function() {
650
+ it('should warn for non objects', function() {
651
typeCheckFail(
652
PropTypes.shape({}),
653
'some string',
@@ -662,25 +662,25 @@ describe('ReactPropTypes', function() {
662
);
663
});
664
665
- it("should not warn for empty values", function() {
665
+ it('should not warn for empty values', function() {
666
typeCheckPass(PropTypes.shape({}), undefined);
667
typeCheckPass(PropTypes.shape({}), null);
668
typeCheckPass(PropTypes.shape({}), {});
669
});
670
671
- it("should not warn for an empty object", function() {
671
+ it('should not warn for an empty object', function() {
672
typeCheckPass(PropTypes.shape({}).isRequired, {});
673
});
674
675
- it("should not warn for non specified types", function() {
675
+ it('should not warn for non specified types', function() {
676
typeCheckPass(PropTypes.shape({}), {key: 1});
677
});
678
679
- it("should not warn for valid types", function() {
679
+ it('should not warn for valid types', function() {
680
typeCheckPass(PropTypes.shape({key: PropTypes.number}), {key: 1});
681
});
682
683
- it("should warn for required valid types", function() {
683
+ it('should warn for required valid types', function() {
684
typeCheckFail(
685
PropTypes.shape({key: PropTypes.number.isRequired}),
686
{},
@@ -688,7 +688,7 @@ describe('ReactPropTypes', function() {
688
);
689
});
690
691
- it("should warn for the first required type", function() {
691
+ it('should warn for the first required type', function() {
692
typeCheckFail(
693
PropTypes.shape({
694
key: PropTypes.number.isRequired,
@@ -699,7 +699,7 @@ describe('ReactPropTypes', function() {
699
);
700
});
701
702
- it("should warn for invalid key types", function() {
702
+ it('should warn for invalid key types', function() {
703
typeCheckFail(PropTypes.shape({key: PropTypes.number}),
704
{key: 'abc'},
705
'Invalid prop `testProp.key` of type `string` supplied to `testComponent`, ' +
@@ -707,7 +707,7 @@ describe('ReactPropTypes', function() {
707
);
708
});
709
710
- it("should be implicitly optional and not warn without values", function() {
710
+ it('should be implicitly optional and not warn without values', function() {
711
typeCheckPass(
712
PropTypes.shape(PropTypes.shape({key: PropTypes.number})), null
713
);
@@ -716,7 +716,7 @@ describe('ReactPropTypes', function() {
716
);
717
});
718
719
- it("should warn for missing required values", function() {
719
+ it('should warn for missing required values', function() {
720
typeCheckFail(
721
PropTypes.shape({key: PropTypes.number}).isRequired,
722
null,
@@ -738,7 +738,7 @@ describe('ReactPropTypes', function() {
738
739
it('should have been called with the right params', function() {
740
var spy = jasmine.createSpy();
741
- var Component = React.createClass({
741
+ Component = React.createClass({
742
propTypes: {num: spy},
743
744
render: function() {
@@ -756,7 +756,7 @@ describe('ReactPropTypes', function() {
756
757
it('should have been called even if the prop is not present', function() {
758
var spy = jasmine.createSpy();
759
- var Component = React.createClass({
759
+ Component = React.createClass({
760
propTypes: {num: spy},
761
762
render: function() {
@@ -778,7 +778,7 @@ describe('ReactPropTypes', function() {
778
}
779
}
780
);
781
- var Component = React.createClass({
781
+ Component = React.createClass({
782
propTypes: {num: spy},
783
784
render: function() {
@@ -790,7 +790,8 @@ describe('ReactPropTypes', function() {
790
instance = ReactTestUtils.renderIntoDocument(instance);
791
expect(console.error.argsForCall.length).toBe(1);
792
expect(console.error.argsForCall[0][0]).toBe(
793
- 'Warning: Failed propType: num must be 5!');
793
+ 'Warning: Failed propType: num must be 5!'
794
+ );
795
});
796
797
it('should not warn if the validator returned null',
@@ -800,7 +801,7 @@ describe('ReactPropTypes', function() {
801
return null;
802
}
803
);
803
- var Component = React.createClass({
804
+ Component = React.createClass({
805
propTypes: {num: spy},
806
807
render: function() {
src/isomorphic/deprecated/__tests__/cloneWithProps-test.js
-2
@@ -15,8 +15,6 @@ require('mock-modules')
15
.dontMock('cloneWithProps')
16
.dontMock('emptyObject');
17
18
-var mocks = require('mocks');
19
-
18
var React;
19
var ReactTestUtils;
20
src/isomorphic/modern/class/__tests__/ReactClassEquivalence-test.js
+2
@@ -9,6 +9,8 @@
9
* @emails react-core
10
*/
11
12
+'use strict';
13
+
14
var MetaMatchers = require('MetaMatchers');
15
16
describe('ReactClassEquivalence', function() {
src/isomorphic/modern/element/__tests__/ReactJSXElement-test.js
+4
-6
@@ -11,8 +11,6 @@
11
12
'use strict';
13
14
-var mocks;
15
-
14
var React;
15
var ReactTestUtils;
16
@@ -22,12 +20,12 @@ describe('ReactJSXElement', function() {
20
beforeEach(function() {
21
require('mock-modules').dumpCache();
22
25
- mocks = require('mocks');
26
-
23
React = require('React');
24
ReactTestUtils = require('ReactTestUtils');
25
Component = class {
30
- render() { return <div />; }
26
+ render() {
27
+ return <div />;
28
+ }
29
};
30
});
31
@@ -145,7 +143,7 @@ describe('ReactJSXElement', function() {
143
expect(React.isValidElement(null)).toEqual(false);
144
expect(React.isValidElement(true)).toEqual(false);
145
expect(React.isValidElement({})).toEqual(false);
148
- expect(React.isValidElement("string")).toEqual(false);
146
+ expect(React.isValidElement('string')).toEqual(false);
147
expect(React.isValidElement(Component)).toEqual(false);
148
});
149
src/isomorphic/modern/element/__tests__/ReactJSXElementValidator-test.js
+18
-16
@@ -29,7 +29,9 @@ describe('ReactJSXElementValidator', function() {
29
ReactTestUtils = require('ReactTestUtils');
30
31
Component = class {
32
- render() { return <div />; }
32
+ render() {
33
+ return <div />;
34
+ }
35
};
36
});
37
@@ -40,7 +42,7 @@ describe('ReactJSXElementValidator', function() {
42
it('warns for keys for arrays of elements in children position', function() {
43
spyOn(console, 'error');
44
43
- <Component>{[<Component />, <Component />]}</Component>;
45
+ void <Component>{[<Component />, <Component />]}</Component>;
46
47
expect(console.error.argsForCall.length).toBe(1);
48
expect(console.error.argsForCall[0][0]).toContain(
@@ -55,7 +57,7 @@ describe('ReactJSXElementValidator', function() {
57
render() {
58
return <Component>{this.props.childSet}</Component>;
59
}
58
- };
60
+ }
61
62
class ComponentWrapper {
63
render() {
@@ -65,7 +67,7 @@ describe('ReactJSXElementValidator', function() {
67
/>
68
);
69
}
68
- };
70
+ }
71
72
ReactTestUtils.renderIntoDocument(<ComponentWrapper />);
73
@@ -92,7 +94,7 @@ describe('ReactJSXElementValidator', function() {
94
}
95
};
96
95
- <Component>{iterable}</Component>;
97
+ void <Component>{iterable}</Component>;
98
99
expect(console.error.argsForCall.length).toBe(1);
100
expect(console.error.argsForCall[0][0]).toContain(
@@ -103,7 +105,7 @@ describe('ReactJSXElementValidator', function() {
105
it('does not warns for arrays of elements with keys', function() {
106
spyOn(console, 'error');
107
106
- <Component>{[<Component key="#1" />, <Component key="#2" />]}</Component>;
108
+ void <Component>{[<Component key="#1" />, <Component key="#2" />]}</Component>;
109
110
expect(console.error.argsForCall.length).toBe(0);
111
});
@@ -126,7 +128,7 @@ describe('ReactJSXElementValidator', function() {
128
}
129
};
130
129
- <Component>{iterable}</Component>
131
+ void <Component>{iterable}</Component>;
132
133
expect(console.error.argsForCall.length).toBe(0);
134
});
@@ -134,7 +136,7 @@ describe('ReactJSXElementValidator', function() {
136
it('warns for numeric keys on objects as children', function() {
137
spyOn(console, 'error');
138
137
- <Component>{frag({1: <Component />, 2: <Component />})}</Component>;
139
+ void <Component>{frag({1: <Component />, 2: <Component />})}</Component>;
140
141
expect(console.error.argsForCall.length).toBe(1);
142
expect(console.error.argsForCall[0][0]).toContain(
@@ -158,7 +160,7 @@ describe('ReactJSXElementValidator', function() {
160
};
161
iterable.entries = iterable['@@iterator'];
162
161
- <Component>{iterable}</Component>;
163
+ void <Component>{iterable}</Component>;
164
165
expect(console.error.argsForCall.length).toBe(0);
166
});
@@ -166,7 +168,7 @@ describe('ReactJSXElementValidator', function() {
168
it('does not warn when the element is directly as children', function() {
169
spyOn(console, 'error');
170
169
- <Component><Component /><Component /></Component>;
171
+ void <Component><Component /><Component /></Component>;
172
173
expect(console.error.argsForCall.length).toBe(0);
174
});
@@ -174,7 +176,7 @@ describe('ReactJSXElementValidator', function() {
176
it('does not warn when the child array contains non-elements', function() {
177
spyOn(console, 'error');
178
177
- <Component>{[ {}, {} ]}</Component>;
179
+ void <Component>{[ {}, {} ]}</Component>;
180
181
expect(console.error.argsForCall.length).toBe(0);
182
});
@@ -215,10 +217,10 @@ describe('ReactJSXElementValidator', function() {
217
var Num = 123;
218
var Div = 'div';
219
spyOn(console, 'error');
218
- <Undefined />;
219
- <Null />;
220
- <True />;
221
- <Num />;
220
+ void <Undefined />;
221
+ void <Null />;
222
+ void <True />;
223
+ void <Num />;
224
expect(console.error.calls.length).toBe(4);
225
expect(console.error.calls[0].args[0]).toContain(
226
'type should not be null, undefined, boolean, or number. It should be ' +
@@ -236,7 +238,7 @@ describe('ReactJSXElementValidator', function() {
238
'type should not be null, undefined, boolean, or number. It should be ' +
239
'a string (for DOM elements) or a ReactClass (for composite components).'
240
);
239
- <Div />;
241
+ void <Div />;
242
expect(console.error.calls.length).toBe(4);
243
});
244
src/renderers/dom/client/__tests__/ReactDOM-test.js
+4
-4
@@ -45,13 +45,13 @@ describe('ReactDOM', function() {
45
});
46
*/
47
48
- it("allows a DOM element to be used with a string", function() {
48
+ it('allows a DOM element to be used with a string', function() {
49
var element = React.createElement('div', {className: 'foo'});
50
var instance = ReactTestUtils.renderIntoDocument(element);
51
expect(React.findDOMNode(instance).tagName).toBe('DIV');
52
});
53
54
- it("should allow children to be passed as an argument", function() {
54
+ it('should allow children to be passed as an argument', function() {
55
var argDiv = ReactTestUtils.renderIntoDocument(
56
div(null, 'child')
57
);
@@ -59,7 +59,7 @@ describe('ReactDOM', function() {
59
expect(argNode.innerHTML).toBe('child');
60
});
61
62
- it("should overwrite props.children with children argument", function() {
62
+ it('should overwrite props.children with children argument', function() {
63
var conflictDiv = ReactTestUtils.renderIntoDocument(
64
div({children: 'fakechild'}, 'child')
65
);
@@ -71,7 +71,7 @@ describe('ReactDOM', function() {
71
* We need to make sure that updates occur to the actual node that's in the
72
* DOM, instead of a stale cache.
73
*/
74
- it("should purge the DOM cache when removing nodes", function() {
74
+ it('should purge the DOM cache when removing nodes', function() {
75
var myDiv = ReactTestUtils.renderIntoDocument(
76
<div>
77
<div key="theDog" className="dog" />,
src/renderers/dom/client/__tests__/ReactDOMIDOperations-test.js
+3
-3
@@ -18,8 +18,8 @@ describe('ReactDOMIDOperations', function() {
18
var keyOf = require('keyOf');
19
20
it('should disallow updating special properties', function() {
21
- spyOn(ReactMount, "getNode");
22
- spyOn(DOMPropertyOperations, "setValueForProperty");
21
+ spyOn(ReactMount, 'getNode');
22
+ spyOn(DOMPropertyOperations, 'setValueForProperty');
23
24
expect(function() {
25
ReactDOMIDOperations.updatePropertyByID(
@@ -40,7 +40,7 @@ describe('ReactDOMIDOperations', function() {
40
41
it('should update innerHTML and preserve whitespace', function() {
42
var stubNode = document.createElement('div');
43
- spyOn(ReactMount, "getNode").andReturn(stubNode);
43
+ spyOn(ReactMount, 'getNode').andReturn(stubNode);
44
45
var html = '\n \t <span> \n testContent \t </span> \n \t';
46
src/renderers/dom/client/__tests__/ReactMount-test.js
+16
-14
@@ -169,25 +169,27 @@ describe('ReactMount', function() {
169
);
170
});
171
172
- (WebComponents === undefined ? xit : it)
173
- ('should allow mounting/unmounting to document fragment container', function() {
174
- var shadowRoot;
175
- var proto = Object.create(HTMLElement.prototype, {
176
- createdCallback: {
177
- value: function() {
172
+ if (WebComponents !== undefined) {
173
+ it('should allow mounting/unmounting to document fragment container',
174
+ function() {
175
+ var shadowRoot;
176
+ var proto = Object.create(HTMLElement.prototype, {
177
+ createdCallback: {
178
+ value: function() {
179
shadowRoot = this.createShadowRoot();
180
React.render(<div>Hi, from within a WC!</div>, shadowRoot);
181
expect(shadowRoot.firstChild.tagName).toBe('DIV');
182
React.render(<span>Hi, from within a WC!</span>, shadowRoot);
183
expect(shadowRoot.firstChild.tagName).toBe('SPAN');
184
+ }
185
}
184
- }
186
+ });
187
+ proto.unmount = function() {
188
+ React.unmountComponentAtNode(shadowRoot);
189
+ };
190
+ document.registerElement('x-foo', {prototype: proto});
191
+ var element = document.createElement('x-foo');
192
+ element.unmount();
193
});
186
- proto.unmount = function() {
187
- React.unmountComponentAtNode(shadowRoot);
188
- };
189
- document.registerElement('x-foo', {prototype: proto});
190
- var element = document.createElement('x-foo');
191
- element.unmount();
192
- });
194
+ }
195
});
src/renderers/dom/client/__tests__/ReactMountDestruction-test.js
+1
-1
@@ -14,7 +14,7 @@
14
var React = require('React');
15
16
describe('ReactMount', function() {
17
- it("should destroy a react root upon request", function() {
17
+ it('should destroy a react root upon request', function() {
18
var mainContainerDiv = document.createElement('div');
19
document.body.appendChild(mainContainerDiv);
20
src/renderers/dom/client/__tests__/findDOMNode-test.js
+6
-2
@@ -34,14 +34,18 @@ describe('findDOMNode', function() {
34
});
35
36
it('findDOMNode should reject random objects', function() {
37
- expect(function() {React.findDOMNode({foo: 'bar'});})
37
+ expect(function() {
38
+ React.findDOMNode({foo: 'bar'});
39
+ })
40
.toThrow('Invariant Violation: Element appears to be neither ' +
41
'ReactComponent nor DOMNode (keys: foo)'
42
);
43
});
44
45
it('findDOMNode should reject unmounted objects with render func', function() {
44
- expect(function() {React.findDOMNode({render: function() {}});})
46
+ expect(function() {
47
+ React.findDOMNode({render: function() {}});
48
+ })
49
.toThrow('Invariant Violation: Component (with keys: render) ' +
50
'contains `render` method but is not mounted in the DOM'
51
);
src/renderers/dom/client/eventPlugins/__tests__/AnalyticsEventPlugin-test.js
+3
-5
@@ -18,7 +18,6 @@ describe('AnalyticsEventPlugin', function() {
18
var EventPluginHub;
19
var EventPluginRegistry;
20
var React;
21
- var ReactBrowserEventEmitter;
21
var ReactTestUtils;
22
23
var DefaultEventPluginOrder;
@@ -32,7 +31,6 @@ describe('AnalyticsEventPlugin', function() {
31
EventPluginHub = require('EventPluginHub');
32
EventPluginRegistry = require('EventPluginRegistry');
33
React = require('React');
35
- ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
34
ReactTestUtils = require('ReactTestUtils');
35
36
EventPluginRegistry._resetEventPlugins();
@@ -65,7 +63,7 @@ describe('AnalyticsEventPlugin', function() {
63
return (
64
<div ref="testDiv"
65
data-analytics-id={TEST_ANALYTICS_ID}
68
- data-analytics-events='click,doubleClick'>
66
+ data-analytics-events="click,doubleClick">
67
Test
68
</div>
69
);
@@ -118,8 +116,8 @@ describe('AnalyticsEventPlugin', function() {
116
render: function() {
117
return (
118
<div ref="testDiv"
121
- data-analytics-id='test_invalid_events'
122
- data-analytics-events='click,123'>
119
+ data-analytics-id="test_invalid_events"
120
+ data-analytics-events="click,123">
121
Test
122
</div>
123
);
src/renderers/dom/client/wrappers/__tests__/ReactDOMInput-test.js
+3
-3
@@ -56,7 +56,7 @@ describe('ReactDOMInput', function() {
56
it('should display "foobar" for `defaultValue` of `objToString`', function() {
57
var objToString = {
58
toString: function() {
59
- return "foobar";
59
+ return 'foobar';
60
}
61
};
62
@@ -86,7 +86,7 @@ describe('ReactDOMInput', function() {
86
expect(node.value).toEqual('true');
87
});
88
89
- it("should allow setting `value` to `false`", function() {
89
+ it('should allow setting `value` to `false`', function() {
90
var stub = <input type="text" value="yolo" onChange={emptyFunction} />;
91
stub = ReactTestUtils.renderIntoDocument(stub);
92
var node = React.findDOMNode(stub);
@@ -106,7 +106,7 @@ describe('ReactDOMInput', function() {
106
107
var objToString = {
108
toString: function() {
109
- return "foobar";
109
+ return 'foobar';
110
}
111
};
112
src/renderers/dom/client/wrappers/__tests__/ReactDOMSelect-test.js
+3
-3
@@ -154,7 +154,7 @@ describe('ReactDOMSelect', function() {
154
});
155
156
it('should reset child options selected when they are changed and `value` is set', function() {
157
- var stub = <select multiple={true} value={["a", "b"]} />;
157
+ var stub = <select multiple={true} value={['a', 'b']} />;
158
stub = ReactTestUtils.renderIntoDocument(stub);
159
160
stub.setProps({
@@ -174,7 +174,7 @@ describe('ReactDOMSelect', function() {
174
175
it('should allow setting `value` with `objectToString`', function() {
176
var objectToString = {
177
- animal: "giraffe",
177
+ animal: 'giraffe',
178
toString: function() {
179
return this.animal;
180
}
@@ -194,7 +194,7 @@ describe('ReactDOMSelect', function() {
194
expect(node.options[2].selected).toBe(false); // gorilla
195
196
// Changing the `value` prop should change the selected options.
197
- objectToString.animal = "monkey";
197
+ objectToString.animal = 'monkey';
198
stub.forceUpdate();
199
200
expect(node.options[0].selected).toBe(true); // monkey
src/renderers/dom/client/wrappers/__tests__/ReactDOMTextarea-test.js
+3
-3
@@ -67,7 +67,7 @@ describe('ReactDOMTextarea', function() {
67
it('should display "foobar" for `defaultValue` of `objToString`', function() {
68
var objToString = {
69
toString: function() {
70
- return "foobar";
70
+ return 'foobar';
71
}
72
};
73
@@ -136,7 +136,7 @@ describe('ReactDOMTextarea', function() {
136
137
var objToString = {
138
toString: function() {
139
- return "foo";
139
+ return 'foo';
140
}
141
};
142
stub.replaceProps({value: objToString, onChange: emptyFunction});
@@ -186,7 +186,7 @@ describe('ReactDOMTextarea', function() {
186
spyOn(console, 'error');
187
var obj = {
188
toString: function() {
189
- return "sharkswithlasers";
189
+ return 'sharkswithlasers';
190
}
191
};
192
var node = React.findDOMNode(renderTextarea(<textarea>{obj}</textarea>));
src/renderers/dom/server/__tests__/ReactServerRendering-test.js
-3
@@ -14,7 +14,6 @@
14
require('mock-modules')
15
.dontMock('ExecutionEnvironment')
16
.dontMock('React')
17
- .dontMock('ReactMount')
17
.dontMock('ReactServerRendering')
18
.dontMock('ReactTestUtils')
19
.dontMock('ReactMarkupChecksum');
@@ -24,7 +23,6 @@ var mocks = require('mocks');
23
var ExecutionEnvironment;
24
var React;
25
var ReactMarkupChecksum;
27
-var ReactMount;
26
var ReactReconcileTransaction;
27
var ReactTestUtils;
28
var ReactServerRendering;
@@ -36,7 +34,6 @@ describe('ReactServerRendering', function() {
34
require('mock-modules').dumpCache();
35
React = require('React');
36
ReactMarkupChecksum = require('ReactMarkupChecksum');
39
- ReactMount = require('ReactMount');
37
ReactTestUtils = require('ReactTestUtils');
38
ReactReconcileTransaction = require('ReactReconcileTransaction');
39
src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js
+5
-1
@@ -212,7 +212,11 @@ describe('DOMPropertyOperations', function() {
212
it('should convert attribute values to string first', function() {
213
// Browsers default to this behavior, but some test environments do not.
214
// This ensures that we have consistent behavior.
215
- var obj = {toString: function() { return '<html>'; }};
215
+ var obj = {
216
+ toString: function() {
217
+ return '<html>';
218
+ }
219
+ };
220
DOMPropertyOperations.setValueForProperty(stubNode, 'role', obj);
221
expect(stubNode.getAttribute('role')).toBe('<html>');
222
});
src/renderers/dom/shared/__tests__/Danger-test.js
+1
-1
@@ -99,7 +99,7 @@ describe('Danger', function() {
99
'Invariant Violation: dangerouslyRenderMarkup(...): Missing markup.'
100
);
101
102
- spyOn(console, "error");
102
+ spyOn(console, 'error');
103
104
var renderedMarkup = Danger.dangerouslyRenderMarkup(['<p></p><p></p>']);
105
var args = console.error.argsForCall[0];
src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
+47
-43
@@ -25,7 +25,7 @@ describe('ReactDOMComponent', function() {
25
ReactTestUtils = require('ReactTestUtils');
26
});
27
28
- it("should handle className", function() {
28
+ it('should handle className', function() {
29
var container = document.createElement('div');
30
React.render(<div style={{}} />, container);
31
@@ -37,7 +37,7 @@ describe('ReactDOMComponent', function() {
37
expect(container.firstChild.className).toEqual('');
38
});
39
40
- it("should gracefully handle various style value types", function() {
40
+ it('should gracefully handle various style value types', function() {
41
var container = document.createElement('div');
42
React.render(<div style={{}} />, container);
43
var stubStyle = container.firstChild.style;
@@ -59,7 +59,7 @@ describe('ReactDOMComponent', function() {
59
});
60
61
// TODO: (poshannessy) deprecate this pattern.
62
- it("should update styles when mutating style object", function() {
62
+ it('should update styles when mutating style object', function() {
63
// not actually used. Just to suppress the style mutation warning
64
spyOn(console, 'error');
65
@@ -138,7 +138,7 @@ describe('ReactDOMComponent', function() {
138
expect(console.error.argsForCall.length).toBe(2);
139
});
140
141
- it("should update styles if initially null", function() {
141
+ it('should update styles if initially null', function() {
142
var styles = null;
143
var container = document.createElement('div');
144
React.render(<div style={styles} />, container);
@@ -151,7 +151,7 @@ describe('ReactDOMComponent', function() {
151
expect(stubStyle.display).toEqual('block');
152
});
153
154
- it("should update styles if updated to null multiple times", function() {
154
+ it('should update styles if updated to null multiple times', function() {
155
var styles = null;
156
var container = document.createElement('div');
157
React.render(<div style={styles} />, container);
@@ -172,25 +172,25 @@ describe('ReactDOMComponent', function() {
172
expect(stubStyle.display).toEqual('');
173
});
174
175
- it("should remove attributes", function() {
175
+ it('should remove attributes', function() {
176
var container = document.createElement('div');
177
- React.render(<img height='17' />, container);
177
+ React.render(<img height="17" />, container);
178
179
expect(container.firstChild.hasAttribute('height')).toBe(true);
180
React.render(<img />, container);
181
expect(container.firstChild.hasAttribute('height')).toBe(false);
182
});
183
184
- it("should remove properties", function() {
184
+ it('should remove properties', function() {
185
var container = document.createElement('div');
186
- React.render(<div className='monkey' />, container);
186
+ React.render(<div className="monkey" />, container);
187
188
expect(container.firstChild.className).toEqual('monkey');
189
React.render(<div />, container);
190
expect(container.firstChild.className).toEqual('');
191
});
192
193
- it("should clear a single style prop when changing 'style'", function() {
193
+ it('should clear a single style prop when changing `style`', function() {
194
var styles = {display: 'none', color: 'red'};
195
var container = document.createElement('div');
196
React.render(<div style={styles} />, container);
@@ -203,7 +203,7 @@ describe('ReactDOMComponent', function() {
203
expect(stubStyle.color).toEqual('green');
204
});
205
206
- it("should clear all the styles when removing 'style'", function() {
206
+ it('should clear all the styles when removing `style`', function() {
207
var styles = {display: 'none', color: 'red'};
208
var container = document.createElement('div');
209
React.render(<div style={styles} />, container);
@@ -215,7 +215,7 @@ describe('ReactDOMComponent', function() {
215
expect(stubStyle.color).toEqual('');
216
});
217
218
- it("should update styles when 'style' changes from null to object", function() {
218
+ it('should update styles when `style` changes from null to object', function() {
219
var container = document.createElement('div');
220
var styles = {color: 'red'};
221
React.render(<div style={styles} />, container);
@@ -226,7 +226,7 @@ describe('ReactDOMComponent', function() {
226
expect(stubStyle.color).toEqual('red');
227
});
228
229
- it("should empty element when removing innerHTML", function() {
229
+ it('should empty element when removing innerHTML', function() {
230
var container = document.createElement('div');
231
React.render(<div dangerouslySetInnerHTML={{__html: ':)'}} />, container);
232
@@ -235,7 +235,7 @@ describe('ReactDOMComponent', function() {
235
expect(container.firstChild.innerHTML).toEqual('');
236
});
237
238
- it("should transition from string content to innerHTML", function() {
238
+ it('should transition from string content to innerHTML', function() {
239
var container = document.createElement('div');
240
React.render(<div>hello</div>, container);
241
@@ -247,7 +247,7 @@ describe('ReactDOMComponent', function() {
247
expect(container.firstChild.innerHTML).toEqual('goodbye');
248
});
249
250
- it("should transition from innerHTML to string content", function() {
250
+ it('should transition from innerHTML to string content', function() {
251
var container = document.createElement('div');
252
React.render(
253
<div dangerouslySetInnerHTML={{__html: 'bonjour'}} />,
@@ -259,7 +259,7 @@ describe('ReactDOMComponent', function() {
259
expect(container.firstChild.innerHTML).toEqual('adieu');
260
});
261
262
- it("should not incur unnecessary DOM mutations", function() {
262
+ it('should not incur unnecessary DOM mutations', function() {
263
var container = document.createElement('div');
264
React.render(<div value="" />, container);
265
@@ -287,7 +287,7 @@ describe('ReactDOMComponent', function() {
287
var genMarkup;
288
289
function quoteRegexp(str) {
290
- return (str + '').replace(/([.?*+\^$\[\]\\(){}|-])/g, "\\$1");
290
+ return (str + '').replace(/([.?*+\^$\[\]\\(){}|-])/g, '\\$1');
291
}
292
293
beforeEach(function() {
@@ -315,7 +315,7 @@ describe('ReactDOMComponent', function() {
315
this.addMatchers({
316
toHaveAttribute: function(attr, value) {
317
var expected = '(?:^|\\s)' + attr + '=[\\\'"]';
318
- if (typeof value != 'undefined') {
318
+ if (typeof value !== 'undefined') {
319
expected += quoteRegexp(value) + '[\\\'"]';
320
}
321
return this.actual.match(new RegExp(expected));
@@ -323,13 +323,13 @@ describe('ReactDOMComponent', function() {
323
});
324
});
325
326
- it("should generate the correct markup with className", function() {
326
+ it('should generate the correct markup with className', function() {
327
expect(genMarkup({className: 'a'})).toHaveAttribute('class', 'a');
328
expect(genMarkup({className: 'a b'})).toHaveAttribute('class', 'a b');
329
expect(genMarkup({className: ''})).toHaveAttribute('class', '');
330
});
331
332
- it("should escape style names and values", function() {
332
+ it('should escape style names and values', function() {
333
expect(genMarkup({
334
style: {'b&ckground': '<3'}
335
})).toHaveAttribute('style', 'b&ckground:<3;');
@@ -340,7 +340,7 @@ describe('ReactDOMComponent', function() {
340
var genMarkup;
341
342
function quoteRegexp(str) {
343
- return (str + '').replace(/([.?*+\^$\[\]\\(){}|-])/g, "\\$1");
343
+ return (str + '').replace(/([.?*+\^$\[\]\\(){}|-])/g, '\\$1');
344
}
345
346
beforeEach(function() {
@@ -368,7 +368,7 @@ describe('ReactDOMComponent', function() {
368
});
369
});
370
371
- it("should handle dangerouslySetInnerHTML", function() {
371
+ it('should handle dangerouslySetInnerHTML', function() {
372
var innerHTML = {__html: 'testContent'};
373
expect(
374
genMarkup({dangerouslySetInnerHTML: innerHTML})
@@ -399,13 +399,13 @@ describe('ReactDOMComponent', function() {
399
var stubComponent = new StubNativeComponent({
400
type: StubNativeComponent,
401
props: props,
402
- _owner: null,
402
+ _owner: null
403
});
404
return stubComponent.mountComponent('test', transaction, {});
405
};
406
});
407
408
- it("should warn against children for void elements", function() {
408
+ it('should warn against children for void elements', function() {
409
spyOn(console, 'error');
410
411
var container = document.createElement('div');
@@ -416,7 +416,7 @@ describe('ReactDOMComponent', function() {
416
expect(console.error.argsForCall[0][0]).toContain('void element');
417
});
418
419
- it("should warn against dangerouslySetInnerHTML for void elements", function() {
419
+ it('should warn against dangerouslySetInnerHTML for void elements', function() {
420
spyOn(console, 'error');
421
422
var container = document.createElement('div');
@@ -430,7 +430,7 @@ describe('ReactDOMComponent', function() {
430
expect(console.error.argsForCall[0][0]).toContain('void element');
431
});
432
433
- it("should treat menuitem as a void element but still create the closing tag", function() {
433
+ it('should treat menuitem as a void element but still create the closing tag', function() {
434
spyOn(console, 'error');
435
436
var container = document.createElement('div');
@@ -445,7 +445,7 @@ describe('ReactDOMComponent', function() {
445
expect(console.error.argsForCall[0][0]).toContain('void element');
446
});
447
448
- it("should validate against multiple children props", function() {
448
+ it('should validate against multiple children props', function() {
449
expect(function() {
450
mountComponent({children: '', dangerouslySetInnerHTML: ''});
451
}).toThrow(
@@ -490,14 +490,14 @@ describe('ReactDOMComponent', function() {
490
}).not.toThrow();
491
});
492
493
- it("should warn about contentEditable and children", function() {
493
+ it('should warn about contentEditable and children', function() {
494
spyOn(console, 'error');
495
mountComponent({contentEditable: true, children: ''});
496
expect(console.error.argsForCall.length).toBe(1);
497
expect(console.error.argsForCall[0][0]).toContain('contentEditable');
498
});
499
500
- it("should validate against invalid styles", function() {
500
+ it('should validate against invalid styles', function() {
501
expect(function() {
502
mountComponent({style: 'display: none'});
503
}).toThrow(
@@ -507,8 +507,7 @@ describe('ReactDOMComponent', function() {
507
);
508
});
509
510
- it("should execute custom event plugin listening behavior", function() {
511
- var React = require('React');
510
+ it('should execute custom event plugin listening behavior', function() {
511
var SimpleEventPlugin = require('SimpleEventPlugin');
512
513
SimpleEventPlugin.didPutListener = mocks.getMockFunction();
@@ -527,8 +526,7 @@ describe('ReactDOMComponent', function() {
526
expect(SimpleEventPlugin.willDeleteListener.mock.calls.length).toBe(1);
527
});
528
530
- it("should handle null and missing properly with event hooks", function() {
531
- var React = require('React');
529
+ it('should handle null and missing properly with event hooks', function() {
530
var SimpleEventPlugin = require('SimpleEventPlugin');
531
532
SimpleEventPlugin.didPutListener = mocks.getMockFunction();
@@ -570,7 +568,7 @@ describe('ReactDOMComponent', function() {
568
container = document.createElement('div');
569
});
570
573
- it("should warn against children for void elements", function() {
571
+ it('should warn against children for void elements', function() {
572
spyOn(console, 'error');
573
574
React.render(<input />, container);
@@ -580,7 +578,7 @@ describe('ReactDOMComponent', function() {
578
expect(console.error.argsForCall[0][0]).toContain('void element');
579
});
580
583
- it("should warn against dangerouslySetInnerHTML for void elements", function() {
581
+ it('should warn against dangerouslySetInnerHTML for void elements', function() {
582
spyOn(console, 'error');
583
584
React.render(<input />, container);
@@ -593,7 +591,7 @@ describe('ReactDOMComponent', function() {
591
expect(console.error.argsForCall[0][0]).toContain('void element');
592
});
593
596
- it("should validate against multiple children props", function() {
594
+ it('should validate against multiple children props', function() {
595
React.render(<div></div>, container);
596
597
expect(function() {
@@ -607,7 +605,7 @@ describe('ReactDOMComponent', function() {
605
);
606
});
607
610
- it("should warn about contentEditable and children", function() {
608
+ it('should warn about contentEditable and children', function() {
609
spyOn(console, 'error');
610
React.render(
611
<div contentEditable><div /></div>,
@@ -617,7 +615,7 @@ describe('ReactDOMComponent', function() {
615
expect(console.error.argsForCall[0][0]).toContain('contentEditable');
616
});
617
620
- it("should validate against invalid styles", function() {
618
+ it('should validate against invalid styles', function() {
619
React.render(<div></div>, container);
620
621
expect(function() {
@@ -629,7 +627,7 @@ describe('ReactDOMComponent', function() {
627
);
628
});
629
632
- it("should properly escape text content and attributes values", function() {
630
+ it('should properly escape text content and attributes values', function() {
631
expect(
632
React.renderToStaticMarkup(
633
React.DOM.div({
@@ -648,7 +646,7 @@ describe('ReactDOMComponent', function() {
646
});
647
648
describe('unmountComponent', function() {
651
- it("should clean up listeners", function() {
649
+ it('should clean up listeners', function() {
650
var React = require('React');
651
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
652
var ReactMount = require('ReactMount');
@@ -784,10 +782,14 @@ describe('ReactDOMComponent', function() {
782
render: () => <Row />
783
});
784
var Table = React.createClass({
787
- render: function() { return <table>{this.props.children}</table>; }
785
+ render: function() {
786
+ return <table>{this.props.children}</table>;
787
+ }
788
});
789
var FancyTable = React.createClass({
790
- render: function() { return <Table>{this.props.children}</Table>; }
790
+ render: function() {
791
+ return <Table>{this.props.children}</Table>;
792
+ }
793
});
794
795
var Viz1 = React.createClass({
@@ -833,7 +835,9 @@ describe('ReactDOMComponent', function() {
835
);
836
837
var Link = React.createClass({
836
- render: function() { return <a>{this.props.children}</a>; }
838
+ render: function() {
839
+ return <a>{this.props.children}</a>;
840
+ }
841
});
842
ReactTestUtils.renderIntoDocument(<Link><div><Link /></div></Link>);
843
expect(console.error.calls.length).toBe(6);
src/renderers/shared/event/__tests__/EventPluginHub-test.js
+1
-1
@@ -26,7 +26,7 @@ describe('EventPluginHub', function() {
26
isEventSupported.mockReturnValueOnce(false);
27
});
28
29
- it("should prevent non-function listeners", function() {
29
+ it('should prevent non-function listeners', function() {
30
expect(function() {
31
EventPluginHub.putListener(1, 'onClick', 'not a function');
32
}).toThrow(
src/renderers/shared/event/eventPlugins/__tests__/ResponderEventPlugin-test.js
+19
-19
@@ -13,10 +13,8 @@
13
14
var EventPluginHub;
15
var EventConstants;
16
-var EventPropagators;
16
var ReactInstanceHandles;
17
var ResponderEventPlugin;
19
-var SyntheticEvent;
18
var EventPluginUtils;
19
20
var GRANDPARENT_ID = '.0';
@@ -25,7 +23,6 @@ var CHILD_ID = '.0.0.0';
23
var CHILD_ID2 = '.0.0.1';
24
25
var topLevelTypes;
28
-var responderEventTypes;
26
27
var touch = function(nodeHandle, i) {
28
return {target: nodeHandle, identifier: i};
@@ -88,7 +85,7 @@ var _touchConfig =
85
),
86
topLevelType: topType,
87
target: targetNodeHandle,
91
- targetID: targetNodeHandle,
88
+ targetID: targetNodeHandle
89
};
90
};
91
@@ -180,13 +177,13 @@ var oneEventLoopTestConfig = function(readableIDToID) {
177
responderTerminationRequest: {},
178
179
// Non-negotiation
183
- responderReject: {}, // These do not bubble capture.
180
+ responderReject: {}, // These do not bubble capture.
181
responderGrant: {},
182
responderStart: {},
183
responderMove: {},
184
responderTerminate: {},
185
responderEnd: {},
189
- responderRelease: {},
186
+ responderRelease: {}
187
};
188
for (var eventName in ret) {
189
for (var readableNodeName in readableIDToID) {
@@ -218,23 +215,29 @@ var registerTestHandlers = function(eventTestConfig, readableIDToID) {
215
'\nFor event test config:\n' + JSON.stringify(eventTestConfig) + '\n'
216
);
217
};
218
+ /*eslint-disable no-loop-func, no-shadow */
219
var registerOneEventType = function(registrationName, eventTypeTestConfig) {
220
for (var readableID in eventTypeTestConfig) {
221
var nodeConfig = eventTypeTestConfig[readableID];
222
var id = readableIDToID[readableID];
223
var handler = nodeConfig.order === NA ? neverFire.bind(null, readableID, registrationName) :
226
- function(readableID, registrationName, nodeConfig, e) {
224
+ // We partially apply readableID and nodeConfig, as they change in the
225
+ // parent closure across iterations.
226
+ function(readableID, nodeConfig, e) {
227
expect(
228
readableID + '->' + registrationName + ' index:' + runs.dispatchCount++
229
).toBe(
230
readableID + '->' + registrationName + ' index:' + nodeConfig.order
231
);
232
- nodeConfig.assertEvent && nodeConfig.assertEvent(e);
232
+ if (nodeConfig.assertEvent) {
233
+ nodeConfig.assertEvent(e);
234
+ }
235
return nodeConfig.returnVal;
234
- }.bind(null, readableID, registrationName, nodeConfig);
236
+ }.bind(null, readableID, nodeConfig);
237
EventPluginHub.putListener(id, registrationName, handler);
238
}
239
};
240
+ /*eslint-enable no-loop-func, no-shadow */
241
for (var eventName in eventTestConfig) {
242
var oneEventTypeTestConfig = eventTestConfig[eventName];
243
var hasTwoPhase = !!oneEventTypeTestConfig.bubbled;
@@ -306,13 +309,13 @@ var run = function(config, hierarchyConfig, nativeEventConfig) {
309
var three = {
310
grandParent: GRANDPARENT_ID,
311
parent: PARENT_ID,
309
- child: CHILD_ID,
312
+ child: CHILD_ID
313
};
314
315
var siblings = {
316
parent: PARENT_ID,
317
childOne: CHILD_ID,
315
- childTwo: CHILD_ID2,
318
+ childTwo: CHILD_ID2
319
};
320
321
describe('ResponderEventPlugin', function() {
@@ -322,10 +325,8 @@ describe('ResponderEventPlugin', function() {
325
EventConstants = require('EventConstants');
326
EventPluginHub = require('EventPluginHub');
327
EventPluginUtils = require('EventPluginUtils');
325
- EventPropagators = require('EventPropagators');
328
ReactInstanceHandles = require('ReactInstanceHandles');
329
ResponderEventPlugin = require('ResponderEventPlugin');
328
- SyntheticEvent = require('SyntheticEvent');
330
331
EventPluginHub.injection.injectInstanceHandle(ReactInstanceHandles);
332
@@ -341,17 +342,16 @@ describe('ResponderEventPlugin', function() {
342
});
343
344
topLevelTypes = EventConstants.topLevelTypes;
344
- responderEventTypes = ResponderEventPlugin.eventTypes;
345
});
346
347
it('should do nothing when no one wants to respond', function() {
348
var config = oneEventLoopTestConfig(three);
349
config.startShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
350
- config.startShouldSetResponder.captured.parent = {order: 1, returnVal: false};
351
- config.startShouldSetResponder.captured.child = {order: 2, returnVal: false};
352
- config.startShouldSetResponder.bubbled.child = {order: 3, returnVal: false};
353
- config.startShouldSetResponder.bubbled.parent = {order: 4, returnVal: false};
354
- config.startShouldSetResponder.bubbled.grandParent = {order: 5, returnVal: false};
350
+ config.startShouldSetResponder.captured.parent = {order: 1, returnVal: false};
351
+ config.startShouldSetResponder.captured.child = {order: 2, returnVal: false};
352
+ config.startShouldSetResponder.bubbled.child = {order: 3, returnVal: false};
353
+ config.startShouldSetResponder.bubbled.parent = {order: 4, returnVal: false};
354
+ config.startShouldSetResponder.bubbled.grandParent = {order: 5, returnVal: false};
355
run(config, three, startConfig(three.child, [three.child], [0]));
356
expect(ResponderEventPlugin.getResponderID()).toBe(null);
357
src/renderers/shared/reconciler/__tests__/ReactComponent-test.js
-4
@@ -12,19 +12,15 @@
12
'use strict';
13
14
var React;
15
-var ReactInstanceMap;
15
var ReactTestUtils;
16
17
var mocks;
19
-var reactComponentExpect;
18
19
describe('ReactComponent', function() {
20
beforeEach(function() {
21
mocks = require('mocks');
22
React = require('React');
25
- ReactInstanceMap = require('ReactInstanceMap');
23
ReactTestUtils = require('ReactTestUtils');
27
- reactComponentExpect = require('reactComponentExpect');
24
});
25
26
it('should throw on invalid render targets', function() {
src/renderers/shared/reconciler/__tests__/ReactComponentLifeCycle-test.js
+3
-3
@@ -207,7 +207,7 @@ describe('ReactComponentLifeCycle', function() {
207
it('throws when accessing state in componentWillMount', function() {
208
var StatefulComponent = React.createClass({
209
componentWillMount: function() {
210
- this.state.yada;
210
+ void this.state.yada;
211
},
212
render: function() {
213
return (
@@ -271,7 +271,7 @@ describe('ReactComponentLifeCycle', function() {
271
expect(this.isMounted()).toBeTruthy();
272
},
273
render: function() {
274
- expect(this.isMounted()).toBeFalsy()
274
+ expect(this.isMounted()).toBeFalsy();
275
return <div/>;
276
}
277
});
@@ -530,7 +530,7 @@ describe('ReactComponentLifeCycle', function() {
530
531
// Since `instance` is a root component, we can set its props. This also
532
// makes Tooltip rerender the tooltip component, which shouldn't throw.
533
- instance.setProps({text: "dos", tooltipText: "two"});
533
+ instance.setProps({text: 'dos', tooltipText: 'two'});
534
});
535
536
it('should not allow setProps() called on an unmounted element',
src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js
+4
-4
@@ -326,7 +326,7 @@ describe('ReactCompositeComponent', function() {
326
expect(() => {
327
this.setState({value: 2}, function() {
328
cbCalled = true;
329
- })
329
+ });
330
}).not.toThrow();
331
},
332
render: function() {
@@ -515,7 +515,7 @@ describe('ReactCompositeComponent', function() {
515
516
render: function() {
517
return <div>{this.context.foo}</div>;
518
- },
518
+ }
519
});
520
521
var component = ReactTestUtils.renderIntoDocument(<Parent />);
@@ -632,7 +632,7 @@ describe('ReactCompositeComponent', function() {
632
633
expect(parentInstance.state.flag).toBe(false);
634
ReactUpdates.batchedUpdates(function() {
635
- parentInstance.setState({flag: true});
635
+ parentInstance.setState({flag: true});
636
});
637
expect(parentInstance.state.flag).toBe(true);
638
@@ -852,7 +852,7 @@ describe('ReactCompositeComponent', function() {
852
853
getChildContext: function() {
854
return {
855
- foo: "bar"
855
+ foo: 'bar'
856
};
857
},
858
src/renderers/shared/reconciler/__tests__/ReactCompositeComponentError-test.js
+1
-2
@@ -12,7 +12,6 @@
12
'use strict';
13
14
var React = require('React');
15
-var ReactTestUtils = require('ReactTestUtils');
15
var ReactErrorUtils = require('ReactErrorUtils');
16
17
describe('ReactCompositeComponent-error', function() {
@@ -26,7 +25,7 @@ describe('ReactCompositeComponent-error', function() {
25
}
26
});
27
29
- new Component();
28
+ void new Component();
29
30
expect(ReactErrorUtils.guard.mostRecentCall.args[1])
31
.toEqual('Component.someHandler');
src/renderers/shared/reconciler/__tests__/ReactCompositeComponentNestedState-test.js
+3
-3
@@ -58,7 +58,7 @@ describe('ReactCompositeComponentNestedState-state', function() {
58
this.setState(function(state, props) {
59
this.props.logger('setState-this', this.state.hue, this.props.color);
60
this.props.logger('setState-args', state.hue, props.color);
61
- return {hue: shade + ' ' + props.color}
61
+ return {hue: shade + ' ' + props.color};
62
}, function() {
63
this.props.logger('after-setState', this.state.hue, this.props.color);
64
});
@@ -79,7 +79,7 @@ describe('ReactCompositeComponentNestedState-state', function() {
79
<button onClick={this.handleHue.bind(this, 'light', 'green')}>
80
Light Green
81
</button>
82
- </div>
82
+ </div>;
83
}
84
});
85
@@ -88,7 +88,7 @@ describe('ReactCompositeComponentNestedState-state', function() {
88
89
var logger = mocks.getMockFunction();
90
91
- var instance = React.render(
91
+ void React.render(
92
<ParentComponent logger={logger} />,
93
container
94
);
src/renderers/shared/reconciler/__tests__/ReactCompositeComponentState-test.js
-6
@@ -14,9 +14,6 @@
14
var mocks = require('mocks');
15
16
var React;
17
-var ReactInstanceMap;
18
-var ReactTestUtils;
19
-var reactComponentExpect;
17
18
var TestComponent;
19
@@ -24,9 +21,6 @@ describe('ReactCompositeComponent-state', function() {
21
22
beforeEach(function() {
23
React = require('React');
27
- ReactInstanceMap = require('ReactInstanceMap');
28
- ReactTestUtils = require('ReactTestUtils');
29
- reactComponentExpect = require('reactComponentExpect');
24
25
TestComponent = React.createClass({
26
peekAtState: function(from, state) {
src/renderers/shared/reconciler/__tests__/ReactEmptyComponent-test.js
+4
-2
@@ -235,7 +235,9 @@ describe('ReactEmptyComponent', function() {
235
it('does not break when updating during mount', function() {
236
var Child = React.createClass({
237
componentDidMount() {
238
- this.props.onMount && this.props.onMount();
238
+ if (this.props.onMount) {
239
+ this.props.onMount();
240
+ }
241
},
242
render() {
243
if (!this.props.visible) {
@@ -262,7 +264,7 @@ describe('ReactEmptyComponent', function() {
264
});
265
266
expect(function() {
265
- ReactTestUtils.renderIntoDocument(<Parent/>)
267
+ ReactTestUtils.renderIntoDocument(<Parent />);
268
}).not.toThrow();
269
});
270
});
src/renderers/shared/reconciler/__tests__/ReactIdentity-test.js
+12
-6
@@ -107,12 +107,12 @@ describe('ReactIdentity', function() {
107
var Wrapper = React.createClass({
108
109
render: function() {
110
- var span1 = <span ref="span1" key={key} />;
111
- var span2 = <span ref="span2" />;
110
+ var s1 = <span ref="span1" key={key} />;
111
+ var s2 = <span ref="span2" />;
112
113
var map = {};
114
- map[key] = span2;
115
- return <div>{[span1, frag(map)]}</div>;
114
+ map[key] = s2;
115
+ return <div>{[s1, frag(map)]}</div>;
116
}
117
118
});
@@ -132,7 +132,10 @@ describe('ReactIdentity', function() {
132
133
it('should allow any character as a key, in a detached parent', function() {
134
var detachedContainer = document.createElement('div');
135
- renderAComponentWithKeyIntoContainer("<'WEIRD/&\\key'>", detachedContainer);
135
+ renderAComponentWithKeyIntoContainer(
136
+ "<'WEIRD/&\\key'>",
137
+ detachedContainer
138
+ );
139
});
140
141
it('should allow any character as a key, in an attached parent', function() {
@@ -141,7 +144,10 @@ describe('ReactIdentity', function() {
144
var attachedContainer = document.createElement('div');
145
document.body.appendChild(attachedContainer);
146
144
- renderAComponentWithKeyIntoContainer("<'WEIRD/&\\key'>", attachedContainer);
147
+ renderAComponentWithKeyIntoContainer(
148
+ "<'WEIRD/&\\key'>",
149
+ attachedContainer
150
+ );
151
152
document.body.removeChild(attachedContainer);
153
});
src/renderers/shared/reconciler/__tests__/ReactInstanceHandles-test.js
+16
-16
@@ -141,7 +141,7 @@ describe('ReactInstanceHandles', function() {
141
expect(function() {
142
ReactMount.findComponentRoot(
143
parentNode,
144
- ReactMount.getID(childNodeB) + ":junk"
144
+ ReactMount.getID(childNodeB) + ':junk'
145
);
146
}).toThrow(
147
'Invariant Violation: findComponentRoot(..., .0.1:0:junk): ' +
@@ -177,14 +177,14 @@ describe('ReactInstanceHandles', function() {
177
});
178
179
describe('traverseTwoPhase', function() {
180
- it("should not traverse when traversing outside DOM", function() {
180
+ it('should not traverse when traversing outside DOM', function() {
181
var targetID = '';
182
var expectedAggregation = [];
183
ReactInstanceHandles.traverseTwoPhase(targetID, argAggregator, ARG);
184
expect(aggregatedArgs).toEqual(expectedAggregation);
185
});
186
187
- it("should traverse two phase across component boundary", function() {
187
+ it('should traverse two phase across component boundary', function() {
188
var parent = renderParentIntoDocument();
189
var targetID = getNodeID(parent.refs.P_P1_C1.refs.DIV_1);
190
var expectedAggregation = [
@@ -202,7 +202,7 @@ describe('ReactInstanceHandles', function() {
202
expect(aggregatedArgs).toEqual(expectedAggregation);
203
});
204
205
- it("should traverse two phase at shallowest node", function() {
205
+ it('should traverse two phase at shallowest node', function() {
206
var parent = renderParentIntoDocument();
207
var targetID = getNodeID(parent.refs.P);
208
var expectedAggregation = [
@@ -215,7 +215,7 @@ describe('ReactInstanceHandles', function() {
215
});
216
217
describe('traverseEnterLeave', function() {
218
- it("should not traverse when enter/leaving outside DOM", function() {
218
+ it('should not traverse when enter/leaving outside DOM', function() {
219
var targetID = '';
220
var expectedAggregation = [];
221
ReactInstanceHandles.traverseEnterLeave(
@@ -224,7 +224,7 @@ describe('ReactInstanceHandles', function() {
224
expect(aggregatedArgs).toEqual(expectedAggregation);
225
});
226
227
- it("should not traverse if enter/leave the same node", function() {
227
+ it('should not traverse if enter/leave the same node', function() {
228
var parent = renderParentIntoDocument();
229
var leaveID = getNodeID(parent.refs.P_P1_C1.refs.DIV_1);
230
var enterID = getNodeID(parent.refs.P_P1_C1.refs.DIV_1);
@@ -235,7 +235,7 @@ describe('ReactInstanceHandles', function() {
235
expect(aggregatedArgs).toEqual(expectedAggregation);
236
});
237
238
- it("should traverse enter/leave to sibling - avoids parent", function() {
238
+ it('should traverse enter/leave to sibling - avoids parent', function() {
239
var parent = renderParentIntoDocument();
240
var leaveID = getNodeID(parent.refs.P_P1_C1.refs.DIV_1);
241
var enterID = getNodeID(parent.refs.P_P1_C1.refs.DIV_2);
@@ -250,7 +250,7 @@ describe('ReactInstanceHandles', function() {
250
expect(aggregatedArgs).toEqual(expectedAggregation);
251
});
252
253
- it("should traverse enter/leave to parent - avoids parent", function() {
253
+ it('should traverse enter/leave to parent - avoids parent', function() {
254
var parent = renderParentIntoDocument();
255
var leaveID = getNodeID(parent.refs.P_P1_C1.refs.DIV_1);
256
var enterID = getNodeID(parent.refs.P_P1_C1.refs.DIV);
@@ -263,7 +263,7 @@ describe('ReactInstanceHandles', function() {
263
expect(aggregatedArgs).toEqual(expectedAggregation);
264
});
265
266
- it("should enter from the window", function() {
266
+ it('should enter from the window', function() {
267
var parent = renderParentIntoDocument();
268
var leaveID = ''; // From the window or outside of the React sandbox.
269
var enterID = getNodeID(parent.refs.P_P1_C1.refs.DIV);
@@ -278,7 +278,7 @@ describe('ReactInstanceHandles', function() {
278
expect(aggregatedArgs).toEqual(expectedAggregation);
279
});
280
281
- it("should enter from the window to the shallowest", function() {
281
+ it('should enter from the window to the shallowest', function() {
282
var parent = renderParentIntoDocument();
283
var leaveID = ''; // From the window or outside of the React sandbox.
284
var enterID = getNodeID(parent.refs.P);
@@ -291,7 +291,7 @@ describe('ReactInstanceHandles', function() {
291
expect(aggregatedArgs).toEqual(expectedAggregation);
292
});
293
294
- it("should leave to the window", function() {
294
+ it('should leave to the window', function() {
295
var parent = renderParentIntoDocument();
296
var enterID = ''; // From the window or outside of the React sandbox.
297
var leaveID = getNodeID(parent.refs.P_P1_C1.refs.DIV);
@@ -306,7 +306,7 @@ describe('ReactInstanceHandles', function() {
306
expect(aggregatedArgs).toEqual(expectedAggregation);
307
});
308
309
- it("should leave to the window from the shallowest", function() {
309
+ it('should leave to the window from the shallowest', function() {
310
var parent = renderParentIntoDocument();
311
var enterID = ''; // From the window or outside of the React sandbox.
312
var leaveID = getNodeID(parent.refs.P_P1_C1.refs.DIV);
@@ -323,7 +323,7 @@ describe('ReactInstanceHandles', function() {
323
});
324
325
describe('getNextDescendantID', function() {
326
- it("should return next descendent from window", function() {
326
+ it('should return next descendent from window', function() {
327
var parent = renderParentIntoDocument();
328
expect(
329
ReactInstanceHandles._getNextDescendantID(
@@ -333,11 +333,11 @@ describe('ReactInstanceHandles', function() {
333
).toBe(getNodeID(parent.refs.P));
334
});
335
336
- it("should return window for next descendent towards window", function() {
336
+ it('should return window for next descendent towards window', function() {
337
expect(ReactInstanceHandles._getNextDescendantID('', '')).toBe('');
338
});
339
340
- it("should return self for next descendent towards self", function() {
340
+ it('should return self for next descendent towards self', function() {
341
var parent = renderParentIntoDocument();
342
expect(
343
ReactInstanceHandles._getNextDescendantID(
@@ -349,7 +349,7 @@ describe('ReactInstanceHandles', function() {
349
});
350
351
describe('getFirstCommonAncestorID', function() {
352
- it("should determine the first common ancestor correctly", function() {
352
+ it('should determine the first common ancestor correctly', function() {
353
var parent = renderParentIntoDocument();
354
var ancestors = [
355
// Common ancestor from window to deep element is ''.
src/renderers/shared/reconciler/__tests__/ReactUpdates-test.js
+5
-4
@@ -530,7 +530,7 @@ describe('ReactUpdates', function() {
530
return {x: 0};
531
},
532
componentDidUpdate: function() {
533
- expect(React.findDOMNode(b).textContent).toBe("B1");
533
+ expect(React.findDOMNode(b).textContent).toBe('B1');
534
aUpdated = true;
535
},
536
render: function() {
@@ -698,7 +698,9 @@ describe('ReactUpdates', function() {
698
});
699
700
var Z = React.createClass({
701
- render: function() { return <div />; },
701
+ render: function() {
702
+ return <div />;
703
+ },
704
componentWillUpdate: function() {
705
x.go();
706
}
@@ -785,7 +787,6 @@ describe('ReactUpdates', function() {
787
return <div />;
788
},
789
componentDidUpdate: function() {
788
- var component = this;
790
ReactUpdates.asap(function() {
791
expect(this).toBe(component);
792
callbackCount++;
@@ -793,7 +794,7 @@ describe('ReactUpdates', function() {
794
callbackCount++;
795
});
796
expect(callbackCount).toBe(1);
796
- }, this);
797
+ }, component);
798
expect(callbackCount).toBe(0);
799
}
800
});
src/renderers/shared/reconciler/__tests__/refs-destruction-test.js
+2
-3
@@ -12,7 +12,6 @@
12
'use strict';
13
14
var React = require('React');
15
-var ReactTestUtils = require('ReactTestUtils');
15
var reactComponentExpect = require('reactComponentExpect');
16
17
var TestComponent = React.createClass({
@@ -34,7 +33,7 @@ describe('refs-destruction', function() {
33
require('mock-modules').dumpCache();
34
});
35
37
- it("should remove refs when destroying the parent", function() {
36
+ it('should remove refs when destroying the parent', function() {
37
var container = document.createElement('div');
38
var testInstance = React.render(<TestComponent />, container);
39
reactComponentExpect(testInstance.refs.theInnerDiv)
@@ -44,7 +43,7 @@ describe('refs-destruction', function() {
43
expect(Object.keys(testInstance.refs || {}).length).toEqual(0);
44
});
45
47
- it("should remove refs when destroying the child", function() {
46
+ it('should remove refs when destroying the child', function() {
47
var container = document.createElement('div');
48
var testInstance = React.render(<TestComponent />, container);
49
reactComponentExpect(testInstance.refs.theInnerDiv)
src/renderers/shared/reconciler/__tests__/refs-test.js
+4
-4
@@ -38,8 +38,8 @@ var ClickCounter = React.createClass({
38
children.push(
39
<div
40
className="clickLogDiv"
41
- key={"clickLog" + i}
42
- ref={"clickLog" + i}
41
+ key={'clickLog' + i}
42
+ ref={'clickLog' + i}
43
/>
44
);
45
}
@@ -122,7 +122,7 @@ describe('reactiverefs', function() {
122
* Ensure that for every click log there is a corresponding ref (from the
123
* perspective of the injected ClickCounter component.
124
*/
125
- it("Should increase refs with an increase in divs", function() {
125
+ it('Should increase refs with an increase in divs', function() {
126
var testRefsComponent = renderTestRefsComponent();
127
var clickIncrementer =
128
ReactTestUtils.findRenderedDOMComponentWithClass(
@@ -195,7 +195,7 @@ describe('ref swapping', function() {
195
}
196
});
197
198
- it("Allow refs to hop around children correctly", function() {
198
+ it('Allow refs to hop around children correctly', function() {
199
var refHopsAround = ReactTestUtils.renderIntoDocument(<RefHopsAround />);
200
201
var firstDiv =
src/shared/utils/__tests__/OrderedMap-test.js
+19
-21
@@ -252,10 +252,8 @@ describe('OrderedMap', function() {
252
expect(om.has(0)).toBe(true);
253
expect(om.has('0')).toBe(true);
254
};
255
- var om = OrderedMap.fromArray(hasZeroStringKey, extractUniqueID);
256
- verifyOM(om);
257
- om = OrderedMap.fromArray(hasZeroNumberKey, extractUniqueID);
258
- verifyOM(om);
255
+ verifyOM(OrderedMap.fromArray(hasZeroStringKey, extractUniqueID));
256
+ verifyOM(OrderedMap.fromArray(hasZeroNumberKey, extractUniqueID));
257
});
258
259
it('should throw when getting invalid public key', function() {
@@ -494,22 +492,22 @@ describe('OrderedMap', function() {
492
});
493
494
it('should compute indices on array that extracted numeric ids', function() {
497
- var om = OrderedMap.fromArray(hasZeroStringKey, extractUniqueID);
498
- expect(om.keyAtIndex(0)).toBe('greg');
499
- expect(om.keyAtIndex(1)).toBe('0');
500
- expect(om.keyAtIndex(2)).toBe('tom');
501
- expect(om.indexOfKey('greg')).toBe(0);
502
- expect(om.indexOfKey('0')).toBe(1);
503
- expect(om.indexOfKey('tom')).toBe(2);
504
-
505
-
506
- var verifyNumericKeys = function(om) {
507
- expect(om.keyAtIndex(0)).toBe('0');
508
- expect(om.keyAtIndex(1)).toBe('2');
509
- expect(om.keyAtIndex(2)).toBe('1');
510
- expect(om.indexOfKey('0')).toBe(0);
511
- expect(om.indexOfKey('2')).toBe(1); // Proove these are not ordered by
512
- expect(om.indexOfKey('1')).toBe(2); // their keys
495
+ var som = OrderedMap.fromArray(hasZeroStringKey, extractUniqueID);
496
+ expect(som.keyAtIndex(0)).toBe('greg');
497
+ expect(som.keyAtIndex(1)).toBe('0');
498
+ expect(som.keyAtIndex(2)).toBe('tom');
499
+ expect(som.indexOfKey('greg')).toBe(0);
500
+ expect(som.indexOfKey('0')).toBe(1);
501
+ expect(som.indexOfKey('tom')).toBe(2);
502
+
503
+
504
+ var verifyNumericKeys = function(nom) {
505
+ expect(nom.keyAtIndex(0)).toBe('0');
506
+ expect(nom.keyAtIndex(1)).toBe('2');
507
+ expect(nom.keyAtIndex(2)).toBe('1');
508
+ expect(nom.indexOfKey('0')).toBe(0);
509
+ expect(nom.indexOfKey('2')).toBe(1); // Prove these are not ordered by
510
+ expect(nom.indexOfKey('1')).toBe(2); // their keys
511
};
512
var omStringNumberKeys =
513
OrderedMap.fromArray(hasAllNumericStringKeys, extractUniqueID);
@@ -731,7 +729,7 @@ describe('OrderedMap', function() {
729
om.forEachRange(duplicate, 0, 3, scope);
730
}).not.toThrow();
731
expect(function() {
734
- om.mapKeyRange(duplicate, 'x' , 3, scope);
732
+ om.mapKeyRange(duplicate, 'x', 3, scope);
733
}).toThrow(
734
'Invariant Violation: mapKeyRange must be given keys ' +
735
'that are present.'
src/shared/utils/__tests__/Transaction-test.js
+4
-2
@@ -56,7 +56,9 @@ describe('Transaction', function() {
56
}
57
},
58
{
59
- initialize: function() { return 'asdf'; },
59
+ initialize: function() {
60
+ return 'asdf';
61
+ },
62
close: function(initResult) {
63
this.secondCloseParam = initResult;
64
}
@@ -201,7 +203,7 @@ describe('Transaction', function() {
203
var isTypeError = false;
204
try {
205
transaction.perform(function() {
204
- throw new TypeError("Thrown in main wrapped operation");
206
+ throw new TypeError('Thrown in main wrapped operation');
207
});
208
} catch (err) {
209
isTypeError = (err instanceof TypeError);