Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 35 additions & 39 deletions src/isomorphic/children/__tests__/ReactChildren-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

'use strict';

const ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');

describe('ReactChildren', () => {
var React;
var ReactTestUtils;
Expand Down Expand Up @@ -878,52 +876,50 @@ describe('ReactChildren', () => {
);
});

if (ReactDOMFeatureFlags.useFiber) {
describe('with fragments enabled', () => {
it('warns for keys for arrays of elements in a fragment', () => {
spyOn(console, 'error');
class ComponentReturningArray extends React.Component {
render() {
return [<div />, <div />];
}
describe('with fragments enabled', () => {
it('warns for keys for arrays of elements in a fragment', () => {
spyOn(console, 'error');
class ComponentReturningArray extends React.Component {
render() {
return [<div />, <div />];
}
}

ReactTestUtils.renderIntoDocument(<ComponentReturningArray />);
ReactTestUtils.renderIntoDocument(<ComponentReturningArray />);

expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: ' +
'Each child in an array or iterator should have a unique "key" prop.' +
' See https://fb.me/react-warning-keys for more information.' +
'\n in ComponentReturningArray (at **)',
);
});
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: ' +
'Each child in an array or iterator should have a unique "key" prop.' +
' See https://fb.me/react-warning-keys for more information.' +
'\n in ComponentReturningArray (at **)',
);
});

it('does not warn when there are keys on elements in a fragment', () => {
spyOn(console, 'error');
class ComponentReturningArray extends React.Component {
render() {
return [<div key="foo" />, <div key="bar" />];
}
it('does not warn when there are keys on elements in a fragment', () => {
spyOn(console, 'error');
class ComponentReturningArray extends React.Component {
render() {
return [<div key="foo" />, <div key="bar" />];
}
}

ReactTestUtils.renderIntoDocument(<ComponentReturningArray />);
ReactTestUtils.renderIntoDocument(<ComponentReturningArray />);

expectDev(console.error.calls.count()).toBe(0);
});
expectDev(console.error.calls.count()).toBe(0);
});

it('warns for keys for arrays at the top level', () => {
spyOn(console, 'error');
it('warns for keys for arrays at the top level', () => {
spyOn(console, 'error');

ReactTestUtils.renderIntoDocument([<div />, <div />]);
ReactTestUtils.renderIntoDocument([<div />, <div />]);

expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: ' +
'Each child in an array or iterator should have a unique "key" prop.' +
' See https://fb.me/react-warning-keys for more information.',
);
});
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: ' +
'Each child in an array or iterator should have a unique "key" prop.' +
' See https://fb.me/react-warning-keys for more information.',
);
});
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
var React;
var ReactDOM;
var ReactTestUtils;
var ReactDOMFeatureFlags;

describe('ReactElement', () => {
var ComponentClass;
Expand All @@ -29,7 +28,6 @@ describe('ReactElement', () => {
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('react-dom/test-utils');
ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
// NOTE: We're explicitly not using JSX here. This is intended to test
// classic JS without JSX.
ComponentClass = class extends React.Component {
Expand Down Expand Up @@ -235,12 +233,7 @@ describe('ReactElement', () => {
var instance = ReactTestUtils.renderIntoDocument(
React.createElement(Wrapper),
);

if (ReactDOMFeatureFlags.useFiber) {
expect(element._owner.stateNode).toBe(instance);
} else {
expect(element._owner.getPublicInstance()).toBe(instance);
}
expect(element._owner.stateNode).toBe(instance);
});

it('merges an additional argument onto the children prop', () => {
Expand Down
14 changes: 4 additions & 10 deletions src/renderers/__tests__/EventPluginHub-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ jest.mock('isEventSupported');
describe('EventPluginHub', () => {
var React;
var ReactTestUtils;
var ReactDOMFeatureFlags;

beforeEach(() => {
jest.resetModules();
React = require('react');
ReactTestUtils = require('react-dom/test-utils');
ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
});

it('should prevent non-function listeners, at dispatch', () => {
Expand All @@ -33,14 +31,10 @@ describe('EventPluginHub', () => {
}).toThrowError(
'Expected `onClick` listener to be a function, instead got a value of `string` type.',
);
if (ReactDOMFeatureFlags.useFiber) {
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Expected `onClick` listener to be a function, instead got a value of `string` type.',
);
} else {
expectDev(console.error.calls.count()).toBe(0);
}
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Expected `onClick` listener to be a function, instead got a value of `string` type.',
);
});

it('should not prevent null listeners, at dispatch', () => {
Expand Down
160 changes: 71 additions & 89 deletions src/renderers/__tests__/ReactComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ var ReactDOM;
var ReactDOMServer;
var ReactTestUtils;

var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');

describe('ReactComponent', () => {
function normalizeCodeLocInfo(str) {
return str && str.replace(/\(at .+?:\d+\)/g, '(at **)');
Expand Down Expand Up @@ -297,21 +295,11 @@ describe('ReactComponent', () => {
'outer componentDidMount',
'start update',
// Previous (equivalent) refs get cleared
...(ReactDOMFeatureFlags.useFiber
? [
// Fiber renders first, resets refs later
'inner 1 render',
'inner 2 render',
'ref 1 got null',
'ref 2 got null',
]
: [
// Stack resets refs before rendering
'ref 1 got null',
'inner 1 render',
'ref 2 got null',
'inner 2 render',
]),
// Fiber renders first, resets refs later
'inner 1 render',
'inner 2 render',
'ref 1 got null',
'ref 2 got null',
'inner 1 componentDidUpdate',
'ref 1 got instance 1',
'inner 2 componentDidUpdate',
Expand Down Expand Up @@ -406,8 +394,7 @@ describe('ReactComponent', () => {
'Objects are not valid as a React child (found: object with keys ' +
'{x, y, z}). If you meant to render a collection of children, use ' +
'an array instead.' +
// Fiber gives a slightly better stack with the nearest host components
(ReactDOMFeatureFlags.useFiber ? '\n in div (at **)' : ''),
'\n in div (at **)',
);
});

Expand All @@ -434,8 +421,7 @@ describe('ReactComponent', () => {
'Objects are not valid as a React child (found: object with keys ' +
'{a, b, c}). If you meant to render a collection of children, use ' +
'an array instead.\n' +
// Fiber gives a slightly better stack with the nearest host components
(ReactDOMFeatureFlags.useFiber ? ' in div (at **)\n' : '') +
' in div (at **)\n' +
' in Foo (at **)',
);
});
Expand All @@ -458,8 +444,7 @@ describe('ReactComponent', () => {
'Objects are not valid as a React child (found: object with keys ' +
'{x, y, z}). If you meant to render a collection of children, use ' +
'an array instead.' +
// Fiber gives a slightly better stack with the nearest host components
(ReactDOMFeatureFlags.useFiber ? '\n in div (at **)' : ''),
'\n in div (at **)',
);
});

Expand All @@ -486,79 +471,76 @@ describe('ReactComponent', () => {
'Objects are not valid as a React child (found: object with keys ' +
'{a, b, c}). If you meant to render a collection of children, use ' +
'an array instead.\n' +
// Fiber gives a slightly better stack with the nearest host components
(ReactDOMFeatureFlags.useFiber ? ' in div (at **)\n' : '') +
' in div (at **)\n' +
' in Foo (at **)',
);
});

if (ReactDOMFeatureFlags.useFiber) {
describe('with new features', () => {
it('warns on function as a return value from a function', () => {
function Foo() {
return Foo;
}
spyOn(console, 'error');
var container = document.createElement('div');
ReactDOM.render(<Foo />, container);
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Functions are not valid as a React child. This may happen if ' +
'you return a Component instead of <Component /> from render. ' +
'Or maybe you meant to call this function rather than return it.\n' +
' in Foo (at **)',
);
});
describe('with new features', () => {
it('warns on function as a return value from a function', () => {
function Foo() {
return Foo;
}
spyOn(console, 'error');
var container = document.createElement('div');
ReactDOM.render(<Foo />, container);
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Functions are not valid as a React child. This may happen if ' +
'you return a Component instead of <Component /> from render. ' +
'Or maybe you meant to call this function rather than return it.\n' +
' in Foo (at **)',
);
});

it('warns on function as a return value from a class', () => {
class Foo extends React.Component {
render() {
return Foo;
}
it('warns on function as a return value from a class', () => {
class Foo extends React.Component {
render() {
return Foo;
}
spyOn(console, 'error');
var container = document.createElement('div');
ReactDOM.render(<Foo />, container);
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Functions are not valid as a React child. This may happen if ' +
'you return a Component instead of <Component /> from render. ' +
'Or maybe you meant to call this function rather than return it.\n' +
' in Foo (at **)',
);
});
}
spyOn(console, 'error');
var container = document.createElement('div');
ReactDOM.render(<Foo />, container);
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Functions are not valid as a React child. This may happen if ' +
'you return a Component instead of <Component /> from render. ' +
'Or maybe you meant to call this function rather than return it.\n' +
' in Foo (at **)',
);
});

it('warns on function as a child to host component', () => {
function Foo() {
return <div><span>{Foo}</span></div>;
}
spyOn(console, 'error');
var container = document.createElement('div');
ReactDOM.render(<Foo />, container);
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Functions are not valid as a React child. This may happen if ' +
'you return a Component instead of <Component /> from render. ' +
'Or maybe you meant to call this function rather than return it.\n' +
' in span (at **)\n' +
' in div (at **)\n' +
' in Foo (at **)',
);
});
it('warns on function as a child to host component', () => {
function Foo() {
return <div><span>{Foo}</span></div>;
}
spyOn(console, 'error');
var container = document.createElement('div');
ReactDOM.render(<Foo />, container);
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Functions are not valid as a React child. This may happen if ' +
'you return a Component instead of <Component /> from render. ' +
'Or maybe you meant to call this function rather than return it.\n' +
' in span (at **)\n' +
' in div (at **)\n' +
' in Foo (at **)',
);
});

it('does not warn for function-as-a-child that gets resolved', () => {
function Bar(props) {
return props.children();
}
function Foo() {
return <Bar>{() => 'Hello'}</Bar>;
}
spyOn(console, 'error');
var container = document.createElement('div');
ReactDOM.render(<Foo />, container);
expect(container.innerHTML).toBe('Hello');
expectDev(console.error.calls.count()).toBe(0);
});
it('does not warn for function-as-a-child that gets resolved', () => {
function Bar(props) {
return props.children();
}
function Foo() {
return <Bar>{() => 'Hello'}</Bar>;
}
spyOn(console, 'error');
var container = document.createElement('div');
ReactDOM.render(<Foo />, container);
expect(container.innerHTML).toBe('Hello');
expectDev(console.error.calls.count()).toBe(0);
});
}
});
});
Loading