Components: Refactor Icon tests to @testing-library/react#44051
Components: Refactor Icon tests to @testing-library/react#44051
Icon tests to @testing-library/react#44051Conversation
1714311 to
1dc79b1
Compare
1dc79b1 to
fa8a107
Compare
Tooltip tests to @testing-library/reactIcon tests to @testing-library/react
|
Size Change: +1.42 kB (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
| [ 'component', { icon: MyComponent } ], | ||
| ] )( '%s', ( label, props ) => { | ||
| it( 'should pass through size', () => { | ||
| it.skip( 'should pass through size', () => { |
There was a problem hiding this comment.
This test is tentatively skipped because it tests the full implementation and I was not sure how this could be replaced.
If you have a better approach to this test, I would like to hear your advice.
There was a problem hiding this comment.
I think we can delete this whole describe.each call, I don't think it adds any value to the tests (especially since it used to check the value of the size prop on the wrapper component, and not the prop's effects on its children)
Icon tests to @testing-library/reactIcon tests to @testing-library/react
ciampo
left a comment
There was a problem hiding this comment.
Thank you for working on this!
Could you add a CHANGELOG entry? 🙏
| [ 'component', { icon: MyComponent } ], | ||
| ] )( '%s', ( label, props ) => { | ||
| it( 'should pass through size', () => { | ||
| it.skip( 'should pass through size', () => { |
There was a problem hiding this comment.
I think we can delete this whole describe.each call, I don't think it adds any value to the tests (especially since it used to check the value of the size prop on the wrapper component, and not the prop's effects on its children)
|
@ciampo
|
| render( <Icon icon={ () => <span data-testid={ testId } /> } /> ); | ||
|
|
||
| expect( wrapper.name() ).toBe( 'span' ); | ||
| expect( screen.getByTestId( testId ) ).toBeInTheDocument(); |
There was a problem hiding this comment.
Does it make sense to use .toBeVisible() which is a bit more specific than .toBeInTheDocument()?
| it( 'renders an svg element with a default width and height of 24', () => { | ||
| const wrapper = shallow( <Icon icon={ svg } /> ); | ||
| render( <Icon data-testid={ testId } icon={ svg } /> ); | ||
| const icon = screen.queryByTestId( testId ); |
There was a problem hiding this comment.
We should be able to use get* instead of query* here, see this for the rationale.
| const icon = screen.queryByTestId( testId ); | |
| const icon = screen.getByTestId( testId ); |
| size={ 32 } | ||
| /> | ||
| ); | ||
| const icon = screen.queryByTestId( testId ); |
There was a problem hiding this comment.
| const icon = screen.queryByTestId( testId ); | |
| const icon = screen.getByTestId( testId ); |
| it( 'renders an svg element and does not override width and height if already specified', () => { | ||
| const wrapper = shallow( <Icon icon={ svg } size={ 32 } /> ); | ||
| render( <Icon data-testid={ testId } icon={ svg } size={ 32 } /> ); | ||
| const icon = screen.queryByTestId( testId ); |
There was a problem hiding this comment.
| const icon = screen.queryByTestId( testId ); | |
| const icon = screen.getByTestId( testId ); |
|
Thank you for the review, @tyxla ! |
| render( <Icon data-testid={ testId } /> ); | ||
|
|
||
| expect( screen.queryByTestId( testId ) ).not.toBeInTheDocument(); | ||
| expect( screen.queryByTestId( testId ) ).toBeNull(); |
There was a problem hiding this comment.
Do you think this additional fix is reasonable?
(.not.toBeVisible() didn't work)
There was a problem hiding this comment.
No, I think .not.toBeInTheDocument() is ideally expressing our goal here; .toBeNull() makes the assertion vague and unclear, while what we have already is pretty transparent IMHO.
There was a problem hiding this comment.
.not.toBeVisible() won't work by design, an element can't be visible if it doesn't exist in the DOM tree, that's why we check with .not.toBeInTheDocument().
There was a problem hiding this comment.
I see!
I have reverted this change and would like to merge it once the test passes.
|
Thank you @tyxla for the additional review ❤️ |
What?
This PR refactors the
Icontests fromenzymeto@testing-library/react.Why?
To clarify the specification of the
Iconcomponent before refactoring to TypeScript in #35744.How?
I rewrote it according to two approaches:
testIdin almost all tests because there is no accesible text and roles.Testing Instructions
Confirm that all tests pass:
npm run test:unit packages/components/src/icon/test/index.jsAlso, it would be easier to see the changes in a split view.