Skip to content

Commit

Permalink
Test :Add a small test for ReactTestUtils to find rendered component …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
Biki-das authored Feb 17, 2023
1 parent 4210655 commit 4fcc918
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/react-dom/src/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,19 @@ describe('ReactTestUtils', () => {
ReactTestUtils.renderIntoDocument(<Component />);
expect(mockArgs.length).toEqual(0);
});
it('should find rendered component with type in document', () => {
class MyComponent extends React.Component {
render() {
return true;
}
}

const instance = ReactTestUtils.renderIntoDocument(<MyComponent />);
const renderedComponentType = ReactTestUtils.findRenderedComponentWithType(
instance,
MyComponent,
);

expect(renderedComponentType).toBe(instance);
});
});

0 comments on commit 4fcc918

Please sign in to comment.