Conversation
…rary/react render
Closed
Member
|
I started refactoring this test last night mostly for fun. Here's my result: describe( 'AlignmentMatrixControl', () => {
it( 'should render', () => {
render( <AlignmentMatrixControl /> );
expect( screen.getByRole( 'grid' ) ).toBeInTheDocument();
} );
it( 'should change value on cell click', async () => {
const onChangeSpy = jest.fn();
render(
<AlignmentMatrixControl
value={ 'center' }
onChange={ onChangeSpy }
/>
);
screen
.getByRole( 'gridcell', {
name: 'center left',
} )
.focus();
expect( onChangeSpy ).toHaveBeenCalledWith( 'center left' );
screen
.getByRole( 'gridcell', {
name: 'bottom center',
} )
.focus();
expect( onChangeSpy ).toHaveBeenCalledWith( 'bottom center' );
} );
} );Edit: I just realized I could get rid of |
|
Size Change: -38 B (0%) Total Size: 1.27 MB
ℹ️ View Unchanged
|
Member
Author
|
Hey, @Mamaduka thanks a lot! I've borrowed some of your ideas, could you take another look? |
Mamaduka
approved these changes
Oct 4, 2022
Member
Author
Oh, of course! Thanks for the great review 🙌 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
This PR refactors the tests of
AlignmentMatrixControlto use@testing-library/react's render instead ofreact-domrender. This addresses one of the changes needed to upgrade to React 18, as touched in #32765.Why?
This addresses one of the changes needed to upgrade to React 18, as touched in #32765.
How?
We're just using the
@testing-library/reactrender method and updating a few utilities, but another special.We're also using the opportunities to refactor all queries to use
screenrather thanquerySelectorandquerySelectorAll.Testing Instructions
Verify tests still pass:
npm run test:unit packages/components/src/alignment-matrix-control/test/index.js