Skip to content

Commit

Permalink
Special case tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Apr 10, 2020
1 parent dbc3756 commit 1352994
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
30 changes: 20 additions & 10 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1724,16 +1724,26 @@ describe('ReactDOMComponent', () => {
<tr />
</div>,
);
}).toErrorDev([
'Warning: validateDOMNesting(...): <tr> cannot appear as a child of ' +
'<div>.' +
'\n in tr (at **)' +
'\n in div (at **)',
'Warning: validateDOMNesting(...): <tr> cannot appear as a child of ' +
'<div>.' +
'\n in tr (at **)' +
'\n in div (at **)',
]);
}).toErrorDev(
ReactFeatureFlags.enableComponentStackLocations
? [
// This warning dedupes since they're in the same component.
'Warning: validateDOMNesting(...): <tr> cannot appear as a child of ' +
'<div>.' +
'\n in tr (at **)' +
'\n in div (at **)',
]
: [
'Warning: validateDOMNesting(...): <tr> cannot appear as a child of ' +
'<div>.' +
'\n in tr (at **)' +
'\n in div (at **)',
'Warning: validateDOMNesting(...): <tr> cannot appear as a child of ' +
'<div>.' +
'\n in tr (at **)' +
'\n in div (at **)',
],
);
});

it('warns on invalid nesting at root', () => {
Expand Down
24 changes: 18 additions & 6 deletions packages/react-reconciler/src/__tests__/ReactFragment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'use strict';

let React;
let ReactFeatureFlags;
let ReactNoop;
let Scheduler;

Expand All @@ -18,6 +19,7 @@ describe('ReactFragment', () => {
jest.resetModules();

React = require('react');
ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
});
Expand Down Expand Up @@ -900,17 +902,27 @@ describe('ReactFragment', () => {
);

ReactNoop.render(<Foo condition={false} />);
expect(() => expect(Scheduler).toFlushWithoutYielding()).toErrorDev(
'Each child in a list should have a unique "key" prop.',
);
if (ReactFeatureFlags.enableComponentStackLocations) {
// The key warning gets deduped because it's in the same component.
expect(Scheduler).toFlushWithoutYielding();
} else {
expect(() => expect(Scheduler).toFlushWithoutYielding()).toErrorDev(
'Each child in a list should have a unique "key" prop.',
);
}

expect(ops).toEqual(['Update Stateful']);
expect(ReactNoop.getChildren()).toEqual([span(), div()]);

ReactNoop.render(<Foo condition={true} />);
expect(() => expect(Scheduler).toFlushWithoutYielding()).toErrorDev(
'Each child in a list should have a unique "key" prop.',
);
if (ReactFeatureFlags.enableComponentStackLocations) {
// The key warning gets deduped because it's in the same component.
expect(Scheduler).toFlushWithoutYielding();
} else {
expect(() => expect(Scheduler).toFlushWithoutYielding()).toErrorDev(
'Each child in a list should have a unique "key" prop.',
);
}

expect(ops).toEqual(['Update Stateful', 'Update Stateful']);
expect(ReactNoop.getChildren()).toEqual([span(), div()]);
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/__tests__/describeComponentFrame-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@

let React;
let ReactDOM;
const ReactFeatureFlags = require('shared/ReactFeatureFlags');

describe('Component stack trace displaying', () => {
beforeEach(() => {
React = require('react');
ReactDOM = require('react-dom');
});

if (ReactFeatureFlags.enableComponentStackLocations) {
it("empty test so Jest doesn't complain", () => {});
return;
}

it('should provide filenames in stack traces', () => {
class Component extends React.Component {
render() {
Expand Down

0 comments on commit 1352994

Please sign in to comment.