Skip to content

Commit 1367f6e

Browse files
committed
Add component indirection to the tests using owner name
This passes in Stack. It helps ensure we supply the correct owner name.
1 parent 6e68f2c commit 1367f6e

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/renderers/shared/shared/__tests__/ReactComponent-test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,25 @@ describe('ReactComponent', () => {
352352
it('includes owner name in the error about badly-typed elements', () => {
353353
spyOn(console, 'error');
354354

355+
var X = undefined;
356+
357+
function Indirection(props) {
358+
return <div>{props.children}</div>;
359+
}
360+
361+
function Bar() {
362+
return <Indirection><X /></Indirection>;
363+
}
364+
355365
function Foo() {
356-
var X = undefined;
357-
return <X />;
366+
return <Bar />;
358367
}
359368

360369
expect(() => ReactTestUtils.renderIntoDocument(<Foo />)).toThrowError(
361370
'Element type is invalid: expected a string (for built-in components) ' +
362371
'or a class/function (for composite components) but got: undefined. ' +
363372
'You likely forgot to export your component from the file it\'s ' +
364-
'defined in. Check the render method of `Foo`.'
373+
'defined in. Check the render method of `Bar`.'
365374
);
366375

367376
// One warning for each element creation

src/renderers/shared/shared/__tests__/ReactStatelessComponent-test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,13 @@ describe('ReactStatelessComponent', () => {
152152
it('should warn when given a string ref', () => {
153153
spyOn(console, 'error');
154154

155-
class Parent extends React.Component {
156-
static displayName = 'Parent';
155+
function Indirection(props) {
156+
return <div>{props.children}</div>;
157+
}
157158

159+
class Parent extends React.Component {
158160
render() {
159-
return <div><StatelessComponent name="A" ref="stateless"/></div>;
161+
return <Indirection><StatelessComponent name="A" ref="stateless"/></Indirection>;
160162
}
161163
}
162164

@@ -169,6 +171,7 @@ describe('ReactStatelessComponent', () => {
169171
'of `Parent`.\n' +
170172
' in StatelessComponent (at **)\n' +
171173
' in div (at **)\n' +
174+
' in Indirection (at **)\n' +
172175
' in Parent (at **)'
173176
);
174177
});
@@ -179,11 +182,13 @@ describe('ReactStatelessComponent', () => {
179182
expect(arg).toBe(null);
180183
});
181184

182-
class Parent extends React.Component {
183-
static displayName = 'Parent';
185+
function Indirection(props) {
186+
return <div>{props.children}</div>;
187+
}
184188

189+
class Parent extends React.Component {
185190
render() {
186-
return <div><StatelessComponent name="A" ref={ref} /></div>;
191+
return <Indirection><StatelessComponent name="A" ref={ref} /></Indirection>;
187192
}
188193
}
189194

@@ -196,6 +201,7 @@ describe('ReactStatelessComponent', () => {
196201
'of `Parent`.\n' +
197202
' in StatelessComponent (at **)\n' +
198203
' in div (at **)\n' +
204+
' in Indirection (at **)\n' +
199205
' in Parent (at **)'
200206
);
201207
});

0 commit comments

Comments
 (0)