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
101 changes: 0 additions & 101 deletions packages/react/src/__tests__/ReactJSXElementValidator-test.internal.js

This file was deleted.

79 changes: 79 additions & 0 deletions packages/react/src/__tests__/ReactJSXElementValidator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,83 @@ describe('ReactJSXElementValidator', () => {
);
}
});

it('warns for fragments with illegal attributes', () => {
spyOnDev(console, 'error');

class Foo extends React.Component {
render() {
return (
<React.Fragment a={1} b={2}>
hello
</React.Fragment>
);
}
}

ReactTestUtils.renderIntoDocument(<Foo />);

if (__DEV__) {
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain('Invalid prop `');
expect(console.error.calls.argsFor(0)[0]).toContain(
'` supplied to `React.Fragment`. React.Fragment ' +
'can only have `key` and `children` props.',
);
}
});

it('warns for fragments with refs', () => {
spyOnDev(console, 'error');

class Foo extends React.Component {
render() {
return (
<React.Fragment
ref={bar => {
this.foo = bar;
}}>
hello
</React.Fragment>
);
}
}

ReactTestUtils.renderIntoDocument(<Foo />);

if (__DEV__) {
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'Invalid attribute `ref` supplied to `React.Fragment`.',
);
}
});

it('does not warn for fragments of multiple elements without keys', () => {
ReactTestUtils.renderIntoDocument(
<React.Fragment>
<span>1</span>
<span>2</span>
</React.Fragment>,
);
});

it('warns for fragments of multiple elements with same key', () => {
spyOnDev(console, 'error');

ReactTestUtils.renderIntoDocument(
<React.Fragment>
<span key="a">1</span>
<span key="a">2</span>
<span key="b">3</span>
</React.Fragment>,
);

if (__DEV__) {
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'Encountered two children with the same key, `a`.',
);
}
});
});