Skip to content

Commit

Permalink
Allow components to render undefined (facebook#21869)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii authored and zhengjitf committed Apr 15, 2022
1 parent 19492c1 commit 9c25e05
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 416 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -924,33 +924,37 @@ describe('ReactDOMServerIntegration', () => {
);
});

describe('components that throw errors', function() {
itThrowsWhenRendering(
'a function returning undefined',
async render => {
const UndefinedComponent = () => undefined;
await render(<UndefinedComponent />, 1);
},
'UndefinedComponent(...): Nothing was returned from render. ' +
'This usually means a return statement is missing. Or, to ' +
'render nothing, return null.',
);
describe('components that render nullish', function() {
itRenders('a function returning null', async render => {
const NullComponent = () => null;
await render(<NullComponent />);
});

itThrowsWhenRendering(
'a class returning undefined',
async render => {
class UndefinedComponent extends React.Component {
render() {
return undefined;
}
itRenders('a class returning null', async render => {
class NullComponent extends React.Component {
render() {
return null;
}
await render(<UndefinedComponent />, 1);
},
'UndefinedComponent(...): Nothing was returned from render. ' +
'This usually means a return statement is missing. Or, to ' +
'render nothing, return null.',
);
}
await render(<NullComponent />);
});

itRenders('a function returning undefined', async render => {
const UndefinedComponent = () => undefined;
await render(<UndefinedComponent />);
});

itRenders('a class returning undefined', async render => {
class UndefinedComponent extends React.Component {
render() {
return undefined;
}
}
await render(<UndefinedComponent />);
});
});

describe('components that throw errors', function() {
itThrowsWhenRendering(
'a function returning an object',
async render => {
Expand Down
Loading

0 comments on commit 9c25e05

Please sign in to comment.