Skip to content

Commit

Permalink
ESLint: Add and enable eslint-plugin-testing-library (#45103)
Browse files Browse the repository at this point in the history
* ESLint: Add and enable eslint-plugin-testing-library

* Intentionally ignore some rules

* Fix a leftover render-result-naming-convention violation

* Intentionally ignore an act() call

* Make no-container and no-node-access warnings instead of errors

* Disable no-container and no-node-access
  • Loading branch information
tyxla committed Oct 21, 2022
1 parent e3d55b9 commit c468f8d
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 5 deletions.
15 changes: 13 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,19 @@ module.exports = {
},
{
files: [ '**/test/**/*.js' ],
excludedFiles: [ '**/*.@(android|ios|native).js' ],
extends: [ 'plugin:jest-dom/recommended' ],
excludedFiles: [
'**/*.@(android|ios|native).js',
'packages/react-native-*/**/*.js',
'test/native/**/*.js',
],
extends: [
'plugin:jest-dom/recommended',
'plugin:testing-library/react',
],
rules: {
'testing-library/no-container': 'off',
'testing-library/no-node-access': 'off',
},
},
{
files: [ 'packages/e2e-test*/**/*.js' ],
Expand Down
248 changes: 247 additions & 1 deletion 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 @@ -188,6 +188,7 @@
"eslint-plugin-jest-dom": "4.0.2",
"eslint-plugin-playwright": "0.8.0",
"eslint-plugin-ssr-friendly": "1.0.6",
"eslint-plugin-testing-library": "5.7.2",
"execa": "4.0.2",
"fast-glob": "3.2.7",
"filenamify": "4.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable testing-library/render-result-naming-convention */

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -102,3 +104,5 @@ describe( 'InnerBlocks', () => {
expect( serialize( block ) ).toMatchSnapshot();
} );
} );

/* eslint-enable testing-library/render-result-naming-convention */
4 changes: 4 additions & 0 deletions packages/blocks/src/api/test/children.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable testing-library/render-result-naming-convention */

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -137,3 +139,5 @@ describe( 'fromDOM', () => {
] );
} );
} );

/* eslint-enable testing-library/render-result-naming-convention */
4 changes: 2 additions & 2 deletions packages/components/src/sandbox/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ describe( 'Sandbox', () => {
};

it( 'should rerender with new emdeded content if html prop changes', () => {
const result = render( <TestWrapper /> );
const { container } = render( <TestWrapper /> );

const iframe = result.container.querySelector( '.components-sandbox' );
const iframe = container.querySelector( '.components-sandbox' );

let sandboxedIframe =
iframe.contentWindow.document.body.querySelector( '.mock-iframe' );
Expand Down
2 changes: 2 additions & 0 deletions packages/data/src/components/with-select/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ describe( 'withSelect', () => {
expect( ChildOriginalComponent ).toHaveBeenCalledTimes( 1 );
expect( ParentOriginalComponent ).toHaveBeenCalledTimes( 1 );

// This is intentionally wrapped in an `act()` call.
// eslint-disable-next-line testing-library/no-unnecessary-act
await act( async () => {
registry.dispatch( 'childRender' ).toggleRender();
} );
Expand Down
4 changes: 4 additions & 0 deletions packages/element/src/test/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable testing-library/render-result-naming-convention */

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -127,3 +129,5 @@ describe( 'element', () => {
} );
} );
} );

/* eslint-enable testing-library/render-result-naming-convention */
4 changes: 4 additions & 0 deletions packages/element/src/test/serialize.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable testing-library/render-result-naming-convention */

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -717,3 +719,5 @@ describe( 'renderStyle()', () => {
} );
} );
} );

/* eslint-enable testing-library/render-result-naming-convention */

0 comments on commit c468f8d

Please sign in to comment.