38
});
39
40
it('returns a complete descriptor according to spec', function() {
41
- var descriptor = React.createFactory(ComponentClass)();
41
+ var descriptor = React.createFactory(ComponentFactory)();
42
expect(descriptor.type).toBe(ComponentClass);
43
expect(descriptor.key).toBe(null);
44
expect(descriptor.ref).toBe(null);
54
});
55
56
it('returns an immutable descriptor', function() {
57
- var descriptor = React.createFactory(ComponentClass)();
57
+ var descriptor = React.createFactory(ComponentFactory)();
58
expect(() => descriptor.type = 'div').toThrow();
59
});
60
61
it('does not reuse the original config object', function() {
62
var config = { foo: 1 };
63
- var descriptor = React.createFactory(ComponentClass)(config);
63
+ var descriptor = React.createFactory(ComponentFactory)(config);
64
expect(descriptor.props.foo).toBe(1);
65
config.foo = 2;
66
expect(descriptor.props.foo).toBe(1);
67
});
68
69
it('extracts key and ref from the config', function() {
70
- var descriptor = React.createFactory(ComponentClass)({
70
+ var descriptor = React.createFactory(ComponentFactory)({
71
key: '12',
72
ref: '34',
73
foo: '56'
79
});
80
81
it('coerces the key to a string', function() {
82
- var descriptor = React.createFactory(ComponentClass)({
82
+ var descriptor = React.createFactory(ComponentFactory)({
83
key: 12,
84
foo: '56'
85
});
90
});
91
92
it('preserves the context on the descriptor', function() {
93
- var Component = React.createFactory(ComponentClass);
93
+ var Component = React.createFactory(ComponentFactory);
94
var descriptor;
95
96
var Wrapper = React.createClass({
112
});
113
114
it('preserves the owner on the descriptor', function() {
115
- var Component = React.createFactory(ComponentClass);
115
+ var Component = React.createFactory(ComponentFactory);
116
var descriptor;
117
118
var Wrapper = React.createClass({
136
it('merges an additional argument onto the children prop', function() {
137
spyOn(console, 'warn');
138
var a = 1;
139
- var descriptor = React.createFactory(ComponentClass)({
139
+ var descriptor = React.createFactory(ComponentFactory)({
140
children: 'text'
141
}, a);
142
expect(descriptor.props.children).toBe(a);
145
146
it('does not override children if no rest args are provided', function() {
147
spyOn(console, 'warn');
148
- var descriptor = React.createFactory(ComponentClass)({
148
+ var descriptor = React.createFactory(ComponentFactory)({
149
children: 'text'
150
});
151
expect(descriptor.props.children).toBe('text');
154
155
it('overrides children if null is provided as an argument', function() {
156
spyOn(console, 'warn');
157
- var descriptor = React.createFactory(ComponentClass)({
157
+ var descriptor = React.createFactory(ComponentFactory)({
158
children: 'text'
159
}, null);
160
expect(descriptor.props.children).toBe(null);
164
it('merges rest arguments onto the children prop in an array', function() {
165
spyOn(console, 'warn');
166
var a = 1, b = 2, c = 3;
167
- var descriptor = React.createFactory(ComponentClass)(null, a, b, c);
167
+ var descriptor = React.createFactory(ComponentFactory)(null, a, b, c);
168
expect(descriptor.props.children).toEqual([1, 2, 3]);
169
expect(console.warn.argsForCall.length).toBe(0);
170
});
171
172
it('warns for keys for arrays of descriptors in rest args', function() {
173
spyOn(console, 'warn');
174
- var Component = React.createFactory(ComponentClass);
174
+ var Component = React.createFactory(ComponentFactory);
175
176
Component(null, [ Component(), Component() ]);
177
183
184
it('does not warn when the descriptor is directly in rest args', function() {
185
spyOn(console, 'warn');
186
- var Component = React.createFactory(ComponentClass);
186
+ var Component = React.createFactory(ComponentFactory);
187
188
Component(null, Component(), Component());
189
192
193
it('does not warn when the array contains a non-descriptor', function() {
194
spyOn(console, 'warn');
195
- var Component = React.createFactory(ComponentClass);
195
+ var Component = React.createFactory(ComponentFactory);
196
197
Component(null, [ {}, {} ]);
198
248
return 21 + x;
249
});
250
expect(factory(21)).toBe(42);
251
- expect(console.warn.argsForCall.length).toBe(1);
252
- expect(console.warn.argsForCall[0][0]).toContain(
253
- 'This JSX uses a plain function.'
254
- );
251
+ // TODO: This warning is temporarily disabled
252
+ expect(console.warn.argsForCall.length).toBe(0);
253
+ // expect(console.warn.argsForCall[0][0]).toContain(
254
+ // 'This JSX uses a plain function.'
255
+ // );
256
});
257
258
+ it('warns but allow a plain function to be immediately invoked', function() {
259
+ spyOn(console, 'warn');
260
+ var result = React.createDescriptor(function (x, y) {
261
+ return 21 + x + y;
262
+ }, 11, 10);
263
+ expect(result).toBe(42);
264
+ // TODO: This warning is temporarily disabled
265
+ expect(console.warn.argsForCall.length).toBe(0);
266
+ // expect(console.warn.argsForCall[0][0]).toContain(
267
+ // 'This JSX uses a plain function.'
268
+ // );
269
+ });
270
+
271
+ it('warns but does not fail on undefined results', function() {
272
+ spyOn(console, 'warn');
273
+ var fn = function () { };
274
+ var result = React.createDescriptor(fn, 1, 2, null);
275
+ expect(result).toBe(undefined);
276
+ // TODO: This warning is temporarily disabled
277
+ expect(console.warn.argsForCall.length).toBe(0);
278
+ // expect(console.warn.argsForCall[0][0]).toContain(
279
+ // 'This JSX uses a plain function.'
280
+ // );
281
+ });
282
+
283
+
284
it('should expose the underlying class from a legacy factory', function() {
285
var Legacy = React.createClass({ render: function() { } });
286
var factory = React.createFactory(Legacy);