From b219f6339adb41dd8720b2d126caef358f4436e4 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 17 Mar 2017 23:13:03 +0000 Subject: [PATCH] Remove ReactFragment dependency from tests --- scripts/fiber/tests-failing.txt | 102 +++++++++++ scripts/fiber/tests-passing.txt | 102 ----------- .../children/__tests__/ReactChildren-test.js | 160 +++++++----------- .../children/__tests__/onlyChild-test.js | 4 +- .../types/__tests__/ReactPropTypes-test.js | 25 +-- src/renderers/__tests__/ReactIdentity-test.js | 20 +-- 6 files changed, 167 insertions(+), 246 deletions(-) diff --git a/scripts/fiber/tests-failing.txt b/scripts/fiber/tests-failing.txt index 325811e74910a..008eb5448030d 100644 --- a/scripts/fiber/tests-failing.txt +++ b/scripts/fiber/tests-failing.txt @@ -1,6 +1,108 @@ +src/isomorphic/children/__tests__/onlyChild-test.js +* should fail when passed two children +* should fail when passed nully values +* should fail when key/value objects +* should not fail when passed interpolated single child +* should return the only child + src/isomorphic/classic/__tests__/ReactContextValidator-test.js * should pass previous context to lifecycles +src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js +* does not return a value from a validator +* does not throw if validator throws +* should warn for invalid strings +* should fail date and regexp correctly +* should not warn for valid values +* should be implicitly optional and not warn without values +* should warn for missing required values +* should warn if called manually in development +* should should accept any value +* should be implicitly optional and not warn without values +* should warn for missing required values +* should warn if called manually in development +* should fail for invalid argument +* should support the arrayOf propTypes +* should support arrayOf with complex types +* should warn with invalid items in the array +* should warn with invalid complex types +* should warn when passed something other than an array +* should not warn when passing an empty array +* should be implicitly optional and not warn without values +* should warn for missing required values +* should warn if called manually in development +* should support components +* should not support multiple components or scalar values +* should be able to define a single child as label +* should warn when passing no label and isRequired is set +* should be implicitly optional and not warn without values +* should warn for missing required values +* should warn if called manually in development +* should warn for invalid instances +* should not warn for valid values +* should be implicitly optional and not warn without values +* should warn for missing required values +* should warn if called manually in development +* should warn for invalid values +* should not warn for valid values +* should not warn for iterables +* should not warn for entry iterables +* should not warn for null/undefined if not required +* should warn for missing required values +* should accept empty array for required props +* should warn if called manually in development +* should fail for invalid argument +* should support the objectOf propTypes +* should support objectOf with complex types +* should warn with invalid items in the object +* should warn with invalid complex types +* should warn when passed something other than an object +* should not warn when passing an empty object +* should be implicitly optional and not warn without values +* should warn for missing required values +* should warn if called manually in development +* should warn but not error for invalid argument +* should warn for invalid values +* should not warn for valid values +* should be implicitly optional and not warn without values +* should warn for missing required values +* should warn if called manually in development +* should warn but not error for invalid argument +* should warn if none of the types are valid +* should not warn if one of the types are valid +* should be implicitly optional and not warn without values +* should warn for missing required values +* should warn if called manually in development +* should warn for non objects +* should not warn for empty values +* should not warn for an empty object +* should not warn for non specified types +* should not warn for valid types +* should warn for required valid types +* should warn for the first required type +* should warn for invalid key types +* should be implicitly optional and not warn without values +* should warn for missing required values +* should warn if called manually in development +* should warn for non-symbol +* should not warn for a polyfilled Symbol +* should have been called with the right params +* should have been called even if the prop is not present +* should have received the validator's return value +* should not warn if the validator returned null + +src/renderers/__tests__/ReactIdentity-test.js +* should allow key property to express identity +* should use composite identity +* should allow any character as a key, in a detached parent +* should allow any character as a key, in an attached parent +* should not allow scripts in keys to execute +* should let restructured components retain their uniqueness +* should let nested restructures retain their uniqueness +* should let text nodes retain their uniqueness +* should retain key during updates in composite components +* should not allow implicit and explicit keys to collide + src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js * gives source code refs for unknown prop warning (ssr) * gives source code refs for unknown prop warning for exact elements (ssr) diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index 6e9cd96e452da..8bc1d4a26e835 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -74,13 +74,6 @@ src/isomorphic/children/__tests__/ReactChildren-test.js * should throw on object * should throw on regex -src/isomorphic/children/__tests__/onlyChild-test.js -* should fail when passed two children -* should fail when passed nully values -* should fail when key/value objects -* should not fail when passed interpolated single child -* should return the only child - src/isomorphic/classic/__tests__/ReactContextValidator-test.js * should filter out context not in contextTypes * should pass next context to lifecycles @@ -231,89 +224,6 @@ src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js * does not blow up with inlined children * does not blow up on key warning with undefined type -src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js -* does not return a value from a validator -* does not throw if validator throws -* should warn for invalid strings -* should fail date and regexp correctly -* should not warn for valid values -* should be implicitly optional and not warn without values -* should warn for missing required values -* should warn if called manually in development -* should should accept any value -* should be implicitly optional and not warn without values -* should warn for missing required values -* should warn if called manually in development -* should fail for invalid argument -* should support the arrayOf propTypes -* should support arrayOf with complex types -* should warn with invalid items in the array -* should warn with invalid complex types -* should warn when passed something other than an array -* should not warn when passing an empty array -* should be implicitly optional and not warn without values -* should warn for missing required values -* should warn if called manually in development -* should support components -* should not support multiple components or scalar values -* should be able to define a single child as label -* should warn when passing no label and isRequired is set -* should be implicitly optional and not warn without values -* should warn for missing required values -* should warn if called manually in development -* should warn for invalid instances -* should not warn for valid values -* should be implicitly optional and not warn without values -* should warn for missing required values -* should warn if called manually in development -* should warn for invalid values -* should not warn for valid values -* should not warn for iterables -* should not warn for entry iterables -* should not warn for null/undefined if not required -* should warn for missing required values -* should accept empty array for required props -* should warn if called manually in development -* should fail for invalid argument -* should support the objectOf propTypes -* should support objectOf with complex types -* should warn with invalid items in the object -* should warn with invalid complex types -* should warn when passed something other than an object -* should not warn when passing an empty object -* should be implicitly optional and not warn without values -* should warn for missing required values -* should warn if called manually in development -* should warn but not error for invalid argument -* should warn for invalid values -* should not warn for valid values -* should be implicitly optional and not warn without values -* should warn for missing required values -* should warn if called manually in development -* should warn but not error for invalid argument -* should warn if none of the types are valid -* should not warn if one of the types are valid -* should be implicitly optional and not warn without values -* should warn for missing required values -* should warn if called manually in development -* should warn for non objects -* should not warn for empty values -* should not warn for an empty object -* should not warn for non specified types -* should not warn for valid types -* should warn for required valid types -* should warn for the first required type -* should warn for invalid key types -* should be implicitly optional and not warn without values -* should warn for missing required values -* should warn if called manually in development -* should warn for non-symbol -* should not warn for a polyfilled Symbol -* should have been called with the right params -* should have been called even if the prop is not present -* should have received the validator's return value -* should not warn if the validator returned null - src/isomorphic/classic/types/__tests__/ReactPropTypesProduction-test.js * should be a no-op * should be a no-op @@ -595,18 +505,6 @@ src/renderers/__tests__/ReactErrorBoundaries-test.js * renders empty output if error boundary does not handle the error * passes first error when two errors happen in commit -src/renderers/__tests__/ReactIdentity-test.js -* should allow key property to express identity -* should use composite identity -* should allow any character as a key, in a detached parent -* should allow any character as a key, in an attached parent -* should not allow scripts in keys to execute -* should let restructured components retain their uniqueness -* should let nested restructures retain their uniqueness -* should let text nodes retain their uniqueness -* should retain key during updates in composite components -* should not allow implicit and explicit keys to collide - src/renderers/__tests__/ReactMockedComponent-test.js * should allow an implicitly mocked component to be rendered without warnings * should allow an implicitly mocked component to be updated diff --git a/src/isomorphic/children/__tests__/ReactChildren-test.js b/src/isomorphic/children/__tests__/ReactChildren-test.js index 6c3421c96d62d..c982509bb3f98 100644 --- a/src/isomorphic/children/__tests__/ReactChildren-test.js +++ b/src/isomorphic/children/__tests__/ReactChildren-test.js @@ -13,12 +13,10 @@ describe('ReactChildren', () => { var React; - var ReactFragment; beforeEach(() => { jest.resetModules(); React = require('react'); - ReactFragment = require('ReactFragment'); }); it('should support identity for simple', () => { @@ -150,8 +148,8 @@ describe('ReactChildren', () => { var instance = (
{div} - {[ReactFragment.create({span})]} - {ReactFragment.create({a: a})} + {[[span]]} + {[a]} {'string'} {1234} {true} @@ -164,8 +162,8 @@ describe('ReactChildren', () => { function assertCalls() { expect(callback.calls.count()).toBe(9); expect(callback).toHaveBeenCalledWith(div, 0); - expect(callback).toHaveBeenCalledWith(, 1); - expect(callback).toHaveBeenCalledWith(, 2); + expect(callback).toHaveBeenCalledWith(span, 1); + expect(callback).toHaveBeenCalledWith(a, 2); expect(callback).toHaveBeenCalledWith('string', 3); expect(callback).toHaveBeenCalledWith(1234, 4); expect(callback).toHaveBeenCalledWith(null, 5); @@ -186,8 +184,8 @@ describe('ReactChildren', () => { assertCalls(); expect(mappedChildren).toEqual([
, - , - , + , + , 'string', 1234, ]); @@ -199,12 +197,7 @@ describe('ReactChildren', () => { var two =
; var three = null; var four =
; - var five =
; - // five is placed into a JS object with a key that is joined to the - // component key attribute. - // Precedence is as follows: - // 1. If grouped in an Object, the object key combined with `key` prop - // 2. If grouped in an Array, the `key` prop, falling back to array index + var five =
; var context = {}; var callback = jasmine.createSpy().and.callFake(function(kid) { @@ -213,34 +206,18 @@ describe('ReactChildren', () => { var instance = (
- {[ - ReactFragment.create({ - firstHalfKey: [zero, one, two], - secondHalfKey: [three, four], - keyFive: five, - }), - ]} + {[[zero, one, two], [three, four], five]}
); function assertCalls() { - expect(callback.calls.count()).toBe(4); - expect(callback).toHaveBeenCalledWith( -
, - 0, - ); - expect(callback).toHaveBeenCalledWith( -
, - 1, - ); - expect(callback).toHaveBeenCalledWith( -
, - 2, - ); - expect(callback).toHaveBeenCalledWith( -
, - 3, - ); + expect(callback.calls.count()).toBe(6); + expect(callback).toHaveBeenCalledWith(zero, 0); + expect(callback).toHaveBeenCalledWith(one, 1); + expect(callback).toHaveBeenCalledWith(two, 2); + expect(callback).toHaveBeenCalledWith(three, 3); + expect(callback).toHaveBeenCalledWith(four, 4); + expect(callback).toHaveBeenCalledWith(five, 5); callback.calls.reset(); } @@ -254,10 +231,10 @@ describe('ReactChildren', () => { ); assertCalls(); expect(mappedChildren).toEqual([ -
, -
, -
, -
, +
, +
, +
, +
, ]); }); @@ -601,52 +578,49 @@ describe('ReactChildren', () => { var two =
; var three = null; var four =
; - var five =
; - // five is placed into a JS object with a key that is joined to the - // component key attribute. - // Precedence is as follows: - // 1. If grouped in an Object, the object key combined with `key` prop - // 2. If grouped in an Array, the `key` prop, falling back to array index + var five =
; var zeroMapped =
; // Key should be overridden var twoMapped =
; // Key should be added even if not supplied! var fourMapped =
; var fiveMapped =
; - var callback = jasmine.createSpy().and.callFake(function(kid, index) { - return index === 0 - ? zeroMapped - : index === 1 ? twoMapped : index === 2 ? fourMapped : fiveMapped; + var callback = jasmine.createSpy().and.callFake(function(kid) { + switch (kid) { + case zero: + return zeroMapped; + case two: + return twoMapped; + case four: + return fourMapped; + case five: + return fiveMapped; + default: + return kid; + } }); - var frag = ReactFragment.create({ - firstHalfKey: [zero, one, two], - secondHalfKey: [three, four], - keyFive: five, - }); + var frag = [[zero, one, two], [three, four], five]; var instance =
{[frag]}
; - expect([frag[0].key, frag[1].key, frag[2].key, frag[3].key]).toEqual([ - 'firstHalfKey/.$keyZero', - 'firstHalfKey/.$keyTwo', - 'secondHalfKey/.$keyFour', - 'keyFive/.$keyFiveInner', - ]); - React.Children.forEach(instance.props.children, callback); - expect(callback.calls.count()).toBe(4); - expect(callback).toHaveBeenCalledWith(frag[0], 0); - expect(callback).toHaveBeenCalledWith(frag[1], 1); - expect(callback).toHaveBeenCalledWith(frag[2], 2); - expect(callback).toHaveBeenCalledWith(frag[3], 3); + expect(callback.calls.count()).toBe(6); + expect(callback).toHaveBeenCalledWith(zero, 0); + expect(callback).toHaveBeenCalledWith(one, 1); + expect(callback).toHaveBeenCalledWith(two, 2); + expect(callback).toHaveBeenCalledWith(three, 3); + expect(callback).toHaveBeenCalledWith(four, 4); + expect(callback).toHaveBeenCalledWith(five, 5); callback.calls.reset(); var mappedChildren = React.Children.map(instance.props.children, callback); - expect(callback.calls.count()).toBe(4); - expect(callback).toHaveBeenCalledWith(frag[0], 0); - expect(callback).toHaveBeenCalledWith(frag[1], 1); - expect(callback).toHaveBeenCalledWith(frag[2], 2); - expect(callback).toHaveBeenCalledWith(frag[3], 3); + expect(callback.calls.count()).toBe(6); + expect(callback).toHaveBeenCalledWith(zero, 0); + expect(callback).toHaveBeenCalledWith(one, 1); + expect(callback).toHaveBeenCalledWith(two, 2); + expect(callback).toHaveBeenCalledWith(three, 3); + expect(callback).toHaveBeenCalledWith(four, 4); + expect(callback).toHaveBeenCalledWith(five, 5); expect(React.Children.count(mappedChildren)).toBe(4); // Keys default to indices. @@ -656,20 +630,16 @@ describe('ReactChildren', () => { mappedChildren[2].key, mappedChildren[3].key, ]).toEqual([ - 'giraffe/.0:$firstHalfKey/.$keyZero', - '.0:$firstHalfKey/.$keyTwo', - 'keyFour/.0:$secondHalfKey/.$keyFour', - '.0:$keyFive/.$keyFiveInner', + 'giraffe/.0:0:$keyZero', + '.0:0:$keyTwo', + '.0:1:$keyFour', + '.0:$keyFive', ]); - expect(mappedChildren[0]).toEqual( -
, - ); - expect(mappedChildren[1]).toEqual(
); - expect(mappedChildren[2]).toEqual( -
, - ); - expect(mappedChildren[3]).toEqual(
); + expect(mappedChildren[0]).toEqual(
); + expect(mappedChildren[1]).toEqual(
); + expect(mappedChildren[2]).toEqual(
); + expect(mappedChildren[3]).toEqual(
); }); it('should retain key across two mappings', () => { @@ -812,27 +782,15 @@ describe('ReactChildren', () => { var two =
; var three = null; var four =
; - var five =
; - // five is placed into a JS object with a key that is joined to the - // component key attribute. - // Precedence is as follows: - // 1. If grouped in an Object, the object key combined with `key` prop - // 2. If grouped in an Array, the `key` prop, falling back to array index + var five =
; var instance = (
- {[ - ReactFragment.create({ - firstHalfKey: [zero, one, two], - secondHalfKey: [three, four], - keyFive: five, - }), - null, - ]} + {[[[zero, one, two], [three, four], five], null]}
); var numberOfChildren = React.Children.count(instance.props.children); - expect(numberOfChildren).toBe(5); + expect(numberOfChildren).toBe(7); }); it('should flatten children to an array', () => { diff --git a/src/isomorphic/children/__tests__/onlyChild-test.js b/src/isomorphic/children/__tests__/onlyChild-test.js index 45ee0f74b3735..606f1be71a668 100644 --- a/src/isomorphic/children/__tests__/onlyChild-test.js +++ b/src/isomorphic/children/__tests__/onlyChild-test.js @@ -13,13 +13,11 @@ describe('onlyChild', () => { var React; - var ReactFragment; var onlyChild; var WrapComponent; beforeEach(() => { React = require('react'); - ReactFragment = require('ReactFragment'); onlyChild = require('onlyChild'); WrapComponent = class extends React.Component { render() { @@ -68,7 +66,7 @@ describe('onlyChild', () => { expect(function() { var instance = ( - {ReactFragment.create({oneThing: })} + {{oneThing: }} ); onlyChild(instance.props.children); diff --git a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js index c5ba572fb25cf..74059935308c9 100644 --- a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js +++ b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js @@ -16,7 +16,6 @@ var checkPropTypes; var checkReactTypeSpec; var React; var ReactDOM; -var ReactFragment; var Component; var MyComponent; @@ -115,7 +114,6 @@ describe('ReactPropTypes', () => { PropTypes = require('ReactPropTypes'); React = require('react'); ReactDOM = require('react-dom'); - ReactFragment = require('ReactFragment'); resetWarningCache(); }); @@ -615,39 +613,20 @@ describe('ReactPropTypes', () => { }); it('should not warn for valid values', () => { - spyOn(console, 'error'); typeCheckPass(PropTypes.node,
); typeCheckPass(PropTypes.node, false); typeCheckPass(PropTypes.node, ); typeCheckPass(PropTypes.node, 'Some string'); typeCheckPass(PropTypes.node, []); - typeCheckPass(PropTypes.node, [ 123, 'Some string',
, ['Another string', [456], , ], , + null, + undefined, ]); - - // Object of renderable things - var frag = ReactFragment.create; - typeCheckPass( - PropTypes.node, - frag({ - k0: 123, - k1: 'Some string', - k2:
, - k3: frag({ - k30: , - k31: frag({k310: }), - k32: 'Another string', - }), - k4: null, - k5: undefined, - }), - ); - expectDev(console.error.calls.count()).toBe(0); }); it('should not warn for iterables', () => { diff --git a/src/renderers/__tests__/ReactIdentity-test.js b/src/renderers/__tests__/ReactIdentity-test.js index e25f1ff049d6e..369c62570660d 100644 --- a/src/renderers/__tests__/ReactIdentity-test.js +++ b/src/renderers/__tests__/ReactIdentity-test.js @@ -13,7 +13,6 @@ var React; var ReactDOM; -var ReactFragment; var ReactTestUtils; describe('ReactIdentity', () => { @@ -21,14 +20,9 @@ describe('ReactIdentity', () => { jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); - ReactFragment = require('ReactFragment'); ReactTestUtils = require('ReactTestUtils'); }); - function frag(obj) { - return ReactFragment.create(obj); - } - it('should allow key property to express identity', () => { var node; var Component = props => ( @@ -72,21 +66,13 @@ describe('ReactIdentity', () => { function renderAComponentWithKeyIntoContainer(key, container) { class Wrapper extends React.Component { render() { - var s1 = ; - var s2 = ; - - var map = {}; - map[key] = s2; - return
{[s1, frag(map)]}
; + return
; } } var instance = ReactDOM.render(, container); - var span1 = instance.refs.span1; - var span2 = instance.refs.span2; - - expect(ReactDOM.findDOMNode(span1)).not.toBe(null); - expect(ReactDOM.findDOMNode(span2)).not.toBe(null); + var span = instance.refs.span; + expect(ReactDOM.findDOMNode(span)).not.toBe(null); } it('should allow any character as a key, in a detached parent', () => {