- Added tests to compare testing of components using different types of element creation
Fixes [#2576] - Fixed Lint warnings and errors
Vipul A M committed
Oct 12, 2015 at 10:24 UTC
b4a6bc89c2b6d6db80e2c7d436a1a596680cab36
1 file changed
+104
src/isomorphic/classic/element/__tests__/ReactElement-test.js
+104
@@ -367,3 +367,107 @@ describe('ReactElement', function() {
367
});
368
369
});
370
+
371
+describe('comparing jsx vs .createFactory() vs .createElement()', function() {
372
+ var Child, mocks;
373
+
374
+ beforeEach(function() {
375
+ require('mock-modules').dumpCache();
376
+ mocks = require('mocks');
377
+ React = require('React');
378
+ ReactDOM = require('ReactDOM');
379
+ ReactTestUtils = require('ReactTestUtils');
380
+
381
+ var metaData = mocks.getMetadata(React.createClass({
382
+ render: function() {
383
+ return React.createElement('div');
384
+ },
385
+ }));
386
+
387
+ Child = mocks.generateFromMetadata(metaData);
388
+
389
+ });
390
+
391
+
392
+ describe('when using jsx only', function() {
393
+ var Parent, instance;
394
+ beforeEach(function() {
395
+ Parent = React.createClass({
396
+ render: function() {
397
+ return (
398
+ <div>
399
+ <Child ref="child" foo="foo value">children value</Child>
400
+ </div>
401
+ );
402
+ },
403
+ });
404
+ instance = ReactTestUtils.renderIntoDocument(<Parent/>);
405
+ });
406
+
407
+ it('should scry children but cannot', function() {
408
+ var children = ReactTestUtils.scryRenderedComponentsWithType(instance, Child);
409
+ expect(children.length).toBe(1);
410
+ });
411
+
412
+ it('does not maintain refs', function() {
413
+ expect(instance.refs.child).not.toBeUndefined();
414
+ });
415
+
416
+ it('can capture Child instantiation calls', function() {
417
+ expect(Child.mock.calls[0][0]).toEqual({ foo: 'foo value', children: 'children value' });
418
+ });
419
+ });
420
+
421
+ describe('when using parent that uses .createFactory()', function() {
422
+ var factory, instance;
423
+ beforeEach(function() {
424
+ var childFactory = React.createFactory(Child);
425
+ var Parent = React.createClass({
426
+ render: function() {
427
+ return React.DOM.div({}, childFactory({ ref: 'child', foo: 'foo value' }, 'children value'));
428
+ },
429
+ });
430
+ factory = React.createFactory(Parent);
431
+ instance = ReactTestUtils.renderIntoDocument(factory());
432
+ });
433
+
434
+ it('can properly scry children', function() {
435
+ var children = ReactTestUtils.scryRenderedComponentsWithType(instance, Child);
436
+ expect(children.length).toBe(1);
437
+ });
438
+
439
+ it('does not maintain refs', function() {
440
+ expect(instance.refs.child).not.toBeUndefined();
441
+ });
442
+
443
+ it('can capture Child instantiation calls', function() {
444
+ expect(Child.mock.calls[0][0]).toEqual({ foo: 'foo value', children: 'children value' });
445
+ });
446
+ });
447
+
448
+ describe('when using parent that uses .createElement()', function() {
449
+ var factory, instance;
450
+ beforeEach(function() {
451
+ var Parent = React.createClass({
452
+ render: function() {
453
+ return React.DOM.div({}, React.createElement(Child, { ref: 'child', foo: 'foo value' }, 'children value'));
454
+ },
455
+ });
456
+ factory = React.createFactory(Parent);
457
+ instance = ReactTestUtils.renderIntoDocument(factory());
458
+ });
459
+
460
+ it('should scry children but cannot', function() {
461
+ var children = ReactTestUtils.scryRenderedComponentsWithType(instance, Child);
462
+ expect(children.length).toBe(1);
463
+ });
464
+
465
+ it('does not maintain refs', function() {
466
+ expect(instance.refs.child).not.toBeUndefined();
467
+ });
468
+
469
+ it('can capture Child instantiation calls', function() {
470
+ expect(Child.mock.calls[0][0]).toEqual({ foo: 'foo value', children: 'children value' });
471
+ });
472
+ });
473
+});