Skip to content

Commit 4fcc918

Browse files
authored
Test :Add a small test for ReactTestUtils to find rendered component with type in document (#24368)
I tried to write test for the ReactTestUtils to find rendered component with type in document Tests before this PR ![Windows PowerShell 4_13_2022 11_35_24 PM](https://user-images.githubusercontent.com/72331432/163243620-40eb753c-4136-4793-a628-efcf9e004562.png) Tests after this PR ![Windows PowerShell 4_13_2022 11_35_30 PM](https://user-images.githubusercontent.com/72331432/163244704-cd17f0e3-7289-4794-895a-be03753e46de.png)
1 parent 4210655 commit 4fcc918

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/react-dom/src/__tests__/ReactTestUtils-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,19 @@ describe('ReactTestUtils', () => {
463463
ReactTestUtils.renderIntoDocument(<Component />);
464464
expect(mockArgs.length).toEqual(0);
465465
});
466+
it('should find rendered component with type in document', () => {
467+
class MyComponent extends React.Component {
468+
render() {
469+
return true;
470+
}
471+
}
472+
473+
const instance = ReactTestUtils.renderIntoDocument(<MyComponent />);
474+
const renderedComponentType = ReactTestUtils.findRenderedComponentWithType(
475+
instance,
476+
MyComponent,
477+
);
478+
479+
expect(renderedComponentType).toBe(instance);
480+
});
466481
});

0 commit comments

Comments
 (0)