Skip to content

Commit

Permalink
ESLint: Fix jest-dom/prefer-in-document rule violations (#44939)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Oct 14, 2022
1 parent 51c85cc commit 7cda3f0
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe( 'DownloadableBlockListItem', () => {
);
const author = screen.queryByText( `by ${ plugin.author }` );
const description = screen.queryByText( plugin.description );
expect( author ).not.toBeNull();
expect( description ).not.toBeNull();
expect( author ).toBeInTheDocument();
expect( description ).toBeInTheDocument();
} );

it( 'should show installing status when installing the block', () => {
Expand All @@ -47,7 +47,7 @@ describe( 'DownloadableBlockListItem', () => {
<DownloadableBlockListItem onClick={ jest.fn() } item={ plugin } />
);
const statusLabel = screen.queryByText( 'Installing…' );
expect( statusLabel ).not.toBeNull();
expect( statusLabel ).toBeInTheDocument();
} );

it( "should be disabled when a plugin can't be installed", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe( 'BlockBreadcrumb', () => {
const rootLabelText = screen.getByText( 'Tuhinga' );
const rootLabelTextDefault = screen.queryByText( 'Document' );

expect( rootLabelTextDefault ).toBeNull();
expect( rootLabelTextDefault ).not.toBeInTheDocument();
expect( rootLabelText ).toBeInTheDocument();
} );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ describe( 'BlockSwitcherDropdownMenu', () => {
screen.getByRole( 'menu', {
name: 'Block Name',
} )
).getAllByRole( 'menuitem' )
).toHaveLength( 1 );
).getByRole( 'menuitem' )
).toBeInTheDocument();
} );
} );
} );
2 changes: 1 addition & 1 deletion packages/components/src/combobox-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe.each( [

// No options are rendered if no match is found
await user.keyboard( unmatchedString );
expect( screen.queryByRole( 'option' ) ).toBeNull();
expect( screen.queryByRole( 'option' ) ).not.toBeInTheDocument();

// Clearing the input renders all options again
await user.clear( input );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe( 'withNotices operations', () => {
act( () => {
handle.current.createNotice( { content: message } );
} );
expect( getByText( message ) ).not.toBeNull();
expect( getByText( message ) ).toBeInTheDocument();
} );

it( 'should create notices of error status with createErrorNotice', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/input-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe( 'InputControl', () => {

const input = screen.getByText( 'Hello' );

expect( input ).toBeTruthy();
expect( input ).toBeInTheDocument();
} );
} );

Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/toolbar/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ describe( 'Toolbar', () => {

expect(
screen.getByLabelText( 'control1', { selector: 'button' } )
).toBeTruthy();
).toBeInTheDocument();
expect(
screen.getByLabelText( 'control2', { selector: 'button' } )
).toBeTruthy();
).toBeInTheDocument();
} );
} );
} );
2 changes: 1 addition & 1 deletion packages/components/src/ui/tooltip/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe( 'props', () => {
<Text>WordPress.org</Text>
</Tooltip>
);
const tooltips = screen.getAllByRole( /tooltip/ );
const tooltips = screen.getAllByRole( /tooltip/i );
// Assert only the base tooltip rendered.
expect( tooltips ).toHaveLength( 1 );
expect( tooltips[ 0 ].id ).toBe( baseTooltipId );
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/src/hooks/test/use-query-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe( 'useQuerySelect', () => {
expect( TestComponent ).toHaveBeenCalledTimes( 2 );

// ensure expected state was rendered
expect( testInstance.findByText( 'bar' ) ).toBeTruthy();
expect( testInstance.getByText( 'bar' ) ).toBeInTheDocument();
} );

it( 'uses memoized selectors', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/editor/src/components/document-outline/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ describe( 'DocumentOutline', () => {
const blocks = [ headingH2 ];
render( <DocumentOutline blocks={ blocks } /> );

const tableOfContentItems = within(
const tableOfContentItem = within(
screen.getByRole( 'list' )
).getAllByRole( 'listitem' );
expect( tableOfContentItems ).toHaveLength( 1 );
expect( tableOfContentItems[ 0 ] ).toHaveTextContent( 'Heading 2' );
).getByRole( 'listitem' );
expect( tableOfContentItem ).toBeInTheDocument();
expect( tableOfContentItem ).toHaveTextContent( 'Heading 2' );
} );

it( 'should render two items when two headings and some paragraphs provided', () => {
Expand Down

0 comments on commit 7cda3f0

Please sign in to comment.