Skip to content

Commit

Permalink
ESLint: Add and enable eslint-plugin-jest-dom (#44983)
Browse files Browse the repository at this point in the history
* ESLint: Enable eslint-plugin-jest-dom

* Fix a couple of false positives
  • Loading branch information
tyxla authored Oct 17, 2022
1 parent 79ec7cf commit 583ac8f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ module.exports = {
excludedFiles: [ 'test/e2e/**/*.js' ],
extends: [ 'plugin:@wordpress/eslint-plugin/test-unit' ],
},
{
files: [ '**/test/**/*.js' ],
excludedFiles: [ '**/*.@(android|ios|native).js' ],
extends: [ 'plugin:jest-dom/recommended' ],
},
{
files: [ 'packages/e2e-test*/**/*.js' ],
excludedFiles: [ 'packages/e2e-test-utils-playwright/**/*.js' ],
Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
"eslint-import-resolver-node": "0.3.4",
"eslint-plugin-eslint-comments": "3.1.2",
"eslint-plugin-import": "2.25.2",
"eslint-plugin-jest-dom": "4.0.2",
"eslint-plugin-playwright": "0.8.0",
"eslint-plugin-ssr-friendly": "1.0.6",
"execa": "4.0.2",
Expand Down
14 changes: 7 additions & 7 deletions packages/components/src/ui/tooltip/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ describe( 'props', () => {
<Text>{ invisibleTooltipTriggerContent }</Text>
</Tooltip>
);
const tooltips = screen.getAllByRole( /tooltip/i );
const tooltip = screen.getByRole( /tooltip/i );
const invisibleTooltipTrigger = screen.getByText(
invisibleTooltipTriggerContent
);
// The invisible tooltip should not render.
expect( tooltips ).toHaveLength( 1 );
// The base tooltip should render only; invisible tooltip should not render.
expect( tooltip ).toBeInTheDocument();
// Assert that the rendered tooltip is indeed the base tooltip.
expect( tooltips[ 0 ].id ).toBe( baseTooltipId );
expect( tooltip.id ).toBe( baseTooltipId );
// But the invisible tooltip's trigger still should have rendered.
expect( invisibleTooltipTrigger ).not.toBeUndefined();
} );
Expand All @@ -70,9 +70,9 @@ describe( 'props', () => {
<Text>WordPress.org</Text>
</Tooltip>
);
const tooltips = screen.getAllByRole( /tooltip/i );
const tooltip = screen.getByRole( /tooltip/i );
// Assert only the base tooltip rendered.
expect( tooltips ).toHaveLength( 1 );
expect( tooltips[ 0 ].id ).toBe( baseTooltipId );
expect( tooltip ).toBeInTheDocument();
expect( tooltip.id ).toBe( baseTooltipId );
} );
} );

0 comments on commit 583ac8f

Please sign in to comment.