Skip to content

Commit

Permalink
test: Fix errors in Rich Text performance test
Browse files Browse the repository at this point in the history
- Remove unnecessary lint warning disable line caused by erroneous
  placement of `screen` argument.
- Query UI components via user-facing attributes, e.g. a11y label.
- Pass mock function to required `onChange` prop to `RichText`
  component.
  • Loading branch information
dcalhoun committed Feb 15, 2023
1 parent 675c29e commit 81212dc
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
changeTextOfRichText,
fireEvent,
measurePerformance,
screen,
} from 'test/helpers';

/**
Expand All @@ -13,23 +14,19 @@ import {
import { RichText } from '@wordpress/block-editor';

describe( 'RichText Performance', () => {
// eslint-disable-next-line jest/no-done-callback
it( 'performance is stable', async ( screen ) => {
it( 'performance is stable', async () => {
const scenario = async () => {
const richTextInput = screen.getByTestId( 'performance' );
const richTextInput = screen.getByLabelText( 'Text input. Empty' );

fireEvent( richTextInput, 'focus' );

changeTextOfRichText(
richTextInput,
'<strong>Bold</strong> <em>italic</em> <s>strikethrough</s> text'
);

// Check if the onChange is called and the state is updated.
expect( changeTextOfRichText ).toHaveBeenCalledTimes( 1 );
};

await measurePerformance( <RichText testID="performance" />, {
await measurePerformance( <RichText onChange={ jest.fn() } />, {
scenario,
} );
} );
Expand Down

0 comments on commit 81212dc

Please sign in to comment.