diff --git a/.eslintrc.js b/.eslintrc.js index 7c853bec85784d..08aa7d7d987f86 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -276,6 +276,21 @@ module.exports = { 'react/no-unused-prop-types': 'off', }, }, + { + files: [ + // matching the pattern of the test runner + '*.test.mjs', + '*.test.js', + '*.test.ts', + '*.test.tsx', + ], + excludedFiles: ['packages/markdown/**/*', 'test/e2e/**/*', 'test/regressions/**/*'], + extends: ['plugin:testing-library/react'], + rules: { + 'testing-library/no-container': 'off', + 'testing-library/prefer-screen-queries': 'off', + }, + }, { files: ['docs/src/modules/components/**/*.js'], rules: { diff --git a/package.json b/package.json index 3a168cb26c50cf..fde932d4e5e83f 100644 --- a/package.json +++ b/package.json @@ -154,6 +154,7 @@ "eslint-plugin-react": "^7.34.4", "eslint-plugin-react-compiler": "0.0.0-experimental-0998c1e-20240625", "eslint-plugin-react-hooks": "^4.6.2", + "eslint-plugin-testing-library": "^6.2.2", "fast-glob": "^3.3.2", "fs-extra": "^11.2.0", "globby": "^14.0.2", diff --git a/packages-internal/test-utils/src/mochaHooks.test.js b/packages-internal/test-utils/src/mochaHooks.test.js index 2628a7a0543d68..eb99a562d19d46 100644 --- a/packages-internal/test-utils/src/mochaHooks.test.js +++ b/packages-internal/test-utils/src/mochaHooks.test.js @@ -83,6 +83,7 @@ describe('mochaHooks', () => { // not wrapped in act() unsafeSetState(1); // make sure effects are flushed + // eslint-disable-next-line testing-library/no-unnecessary-act act(() => {}); }); diff --git a/packages/mui-base/src/Button/Button.test.tsx b/packages/mui-base/src/Button/Button.test.tsx index 95a89a1d7d7d08..5803f9410dac6e 100644 --- a/packages/mui-base/src/Button/Button.test.tsx +++ b/packages/mui-base/src/Button/Button.test.tsx @@ -67,6 +67,7 @@ describe('