Use dump cache and remove factory from ReactElement-test
We need to use dump cache because we don't enable it by default internally. While I'm at it, I might as well kill the ComponentFactory variable which is now just an alias.
Sebastian Markbage committed
Oct 30, 2014 at 02:50 UTC
7f7b7f386aac0276a2b5824438119e5133890afb
1 file changed
+23
-23
src/core/__tests__/ReactElement-test.js
+23
-23
@@ -16,21 +16,21 @@ var ReactElement;
16
var ReactTestUtils;
17
18
describe('ReactElement', function() {
19
- var ComponentFactory;
19
var ComponentClass;
20
21
beforeEach(function() {
22
+ require('mock-modules').dumpCache();
23
+
24
React = require('React');
25
ReactElement = require('ReactElement');
26
ReactTestUtils = require('ReactTestUtils');
26
- ComponentFactory = React.createClass({
27
+ ComponentClass = React.createClass({
28
render: function() { return <div />; }
29
});
29
- ComponentClass = ComponentFactory;
30
});
31
32
it('returns a complete element according to spec', function() {
33
- var element = React.createFactory(ComponentFactory)();
33
+ var element = React.createFactory(ComponentClass)();
34
expect(element.type).toBe(ComponentClass);
35
expect(element.key).toBe(null);
36
expect(element.ref).toBe(null);
@@ -46,20 +46,20 @@ describe('ReactElement', function() {
46
});
47
48
it('returns an immutable element', function() {
49
- var element = React.createFactory(ComponentFactory)();
49
+ var element = React.createFactory(ComponentClass)();
50
expect(() => element.type = 'div').toThrow();
51
});
52
53
it('does not reuse the original config object', function() {
54
var config = { foo: 1 };
55
- var element = React.createFactory(ComponentFactory)(config);
55
+ var element = React.createFactory(ComponentClass)(config);
56
expect(element.props.foo).toBe(1);
57
config.foo = 2;
58
expect(element.props.foo).toBe(1);
59
});
60
61
it('extracts key and ref from the config', function() {
62
- var element = React.createFactory(ComponentFactory)({
62
+ var element = React.createFactory(ComponentClass)({
63
key: '12',
64
ref: '34',
65
foo: '56'
@@ -71,7 +71,7 @@ describe('ReactElement', function() {
71
});
72
73
it('coerces the key to a string', function() {
74
- var element = React.createFactory(ComponentFactory)({
74
+ var element = React.createFactory(ComponentClass)({
75
key: 12,
76
foo: '56'
77
});
@@ -83,7 +83,7 @@ describe('ReactElement', function() {
83
84
it('treats a null key as omitted but warns', function() {
85
spyOn(console, 'warn');
86
- var element = React.createFactory(ComponentFactory)({
86
+ var element = React.createFactory(ComponentClass)({
87
key: null,
88
foo: '56'
89
});
@@ -98,7 +98,7 @@ describe('ReactElement', function() {
98
});
99
100
it('preserves the context on the element', function() {
101
- var Component = React.createFactory(ComponentFactory);
101
+ var Component = React.createFactory(ComponentClass);
102
var element;
103
104
var Wrapper = React.createClass({
@@ -120,7 +120,7 @@ describe('ReactElement', function() {
120
});
121
122
it('preserves the owner on the element', function() {
123
- var Component = React.createFactory(ComponentFactory);
123
+ var Component = React.createFactory(ComponentClass);
124
var element;
125
126
var Wrapper = React.createClass({
@@ -144,7 +144,7 @@ describe('ReactElement', function() {
144
it('merges an additional argument onto the children prop', function() {
145
spyOn(console, 'warn');
146
var a = 1;
147
- var element = React.createFactory(ComponentFactory)({
147
+ var element = React.createFactory(ComponentClass)({
148
children: 'text'
149
}, a);
150
expect(element.props.children).toBe(a);
@@ -153,7 +153,7 @@ describe('ReactElement', function() {
153
154
it('does not override children if no rest args are provided', function() {
155
spyOn(console, 'warn');
156
- var element = React.createFactory(ComponentFactory)({
156
+ var element = React.createFactory(ComponentClass)({
157
children: 'text'
158
});
159
expect(element.props.children).toBe('text');
@@ -162,7 +162,7 @@ describe('ReactElement', function() {
162
163
it('overrides children if null is provided as an argument', function() {
164
spyOn(console, 'warn');
165
- var element = React.createFactory(ComponentFactory)({
165
+ var element = React.createFactory(ComponentClass)({
166
children: 'text'
167
}, null);
168
expect(element.props.children).toBe(null);
@@ -172,14 +172,14 @@ describe('ReactElement', function() {
172
it('merges rest arguments onto the children prop in an array', function() {
173
spyOn(console, 'warn');
174
var a = 1, b = 2, c = 3;
175
- var element = React.createFactory(ComponentFactory)(null, a, b, c);
175
+ var element = React.createFactory(ComponentClass)(null, a, b, c);
176
expect(element.props.children).toEqual([1, 2, 3]);
177
expect(console.warn.argsForCall.length).toBe(0);
178
});
179
180
it('warns for keys for arrays of elements in rest args', function() {
181
spyOn(console, 'warn');
182
- var Component = React.createFactory(ComponentFactory);
182
+ var Component = React.createFactory(ComponentClass);
183
184
Component(null, [ Component(), Component() ]);
185
@@ -191,7 +191,7 @@ describe('ReactElement', function() {
191
192
it('warns for keys for iterables of elements in rest args', function() {
193
spyOn(console, 'warn');
194
- var Component = React.createFactory(ComponentFactory);
194
+ var Component = React.createFactory(ComponentClass);
195
196
var iterable = {
197
'@@iterator': function() {
@@ -215,7 +215,7 @@ describe('ReactElement', function() {
215
216
it('does not warns for arrays of elements with keys', function() {
217
spyOn(console, 'warn');
218
- var Component = React.createFactory(ComponentFactory);
218
+ var Component = React.createFactory(ComponentClass);
219
220
Component(null, [ Component({key: '#1'}), Component({key: '#2'}) ]);
221
@@ -224,7 +224,7 @@ describe('ReactElement', function() {
224
225
it('does not warns for iterable elements with keys', function() {
226
spyOn(console, 'warn');
227
- var Component = React.createFactory(ComponentFactory);
227
+ var Component = React.createFactory(ComponentClass);
228
229
var iterable = {
230
'@@iterator': function() {
@@ -248,7 +248,7 @@ describe('ReactElement', function() {
248
249
it('warns for numeric keys on objects in rest args', function() {
250
spyOn(console, 'warn');
251
- var Component = React.createFactory(ComponentFactory);
251
+ var Component = React.createFactory(ComponentClass);
252
253
Component(null, { 1: Component(), 2: Component() });
254
@@ -260,7 +260,7 @@ describe('ReactElement', function() {
260
261
it('does not warn for numeric keys in entry iterables in rest args', function() {
262
spyOn(console, 'warn');
263
- var Component = React.createFactory(ComponentFactory);
263
+ var Component = React.createFactory(ComponentClass);
264
265
var iterable = {
266
'@@iterator': function() {
@@ -282,7 +282,7 @@ describe('ReactElement', function() {
282
283
it('does not warn when the element is directly in rest args', function() {
284
spyOn(console, 'warn');
285
- var Component = React.createFactory(ComponentFactory);
285
+ var Component = React.createFactory(ComponentClass);
286
287
Component(null, Component(), Component());
288
@@ -291,7 +291,7 @@ describe('ReactElement', function() {
291
292
it('does not warn when the array contains a non-element', function() {
293
spyOn(console, 'warn');
294
- var Component = React.createFactory(ComponentFactory);
294
+ var Component = React.createFactory(ComponentClass);
295
296
Component(null, [ {}, {} ]);
297