Skip to content

Commit 72ff92a

Browse files
committed
Adding a test for the "Unknown" branch when getComponentName() returns a falsy value. The error message in this case not the most descriptive but seems consistent with the getComponentName(type) || 'Unknown' pattern seen in multiple places in this code base.
1 parent 74a3e77 commit 72ff92a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,4 +1022,14 @@ describe('ReactTestRenderer', () => {
10221022
expect(Scheduler).toFlushWithoutYielding();
10231023
ReactTestRenderer.create(<App />);
10241024
});
1025+
1026+
it('calling findByType() with an invalid component will fall back to "Unknown" for component name', () => {
1027+
const App = () => null;
1028+
const renderer = ReactTestRenderer.create(<App />);
1029+
const NonComponent = {};
1030+
1031+
expect(() => {
1032+
renderer.root.findByType(NonComponent);
1033+
}).toThrowError(`No instances found with node type: "Unknown"`);
1034+
});
10251035
});

0 commit comments

Comments
 (0)