From fe6f6a566ab0d19d1a8fe6a54982f40d6f394256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Thu, 23 Sep 2021 13:26:54 +0200 Subject: [PATCH] feat(no-unnecessary-act): make `isStrict` option `true` by default BREAKING CHANGE: `isStrict` option is now `true` by default --- lib/configs/react.ts | 2 +- lib/rules/no-unnecessary-act.ts | 11 ++++++----- tests/__snapshots__/index.test.ts.snap | 7 +------ tests/lib/rules/no-unnecessary-act.test.ts | 19 +++++++++++-------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/configs/react.ts b/lib/configs/react.ts index 13ce9685..f7919d6b 100644 --- a/lib/configs/react.ts +++ b/lib/configs/react.ts @@ -14,7 +14,7 @@ export = { 'testing-library/no-node-access': 'error', 'testing-library/no-promise-in-fire-event': 'error', 'testing-library/no-render-in-setup': 'error', - 'testing-library/no-unnecessary-act': ['error', { isStrict: true }], + 'testing-library/no-unnecessary-act': 'error', 'testing-library/no-wait-for-empty-callback': 'error', 'testing-library/no-wait-for-multiple-assertions': 'error', 'testing-library/prefer-find-by': 'error', diff --git a/lib/rules/no-unnecessary-act.ts b/lib/rules/no-unnecessary-act.ts index 8fc06f67..5bdf4fd2 100644 --- a/lib/rules/no-unnecessary-act.ts +++ b/lib/rules/no-unnecessary-act.ts @@ -27,7 +27,7 @@ export default createTestingLibraryRule({ recommendedConfig: { dom: false, angular: false, - react: ['error', { isStrict: true }], + react: 'error', vue: false, }, }, @@ -40,18 +40,20 @@ export default createTestingLibraryRule({ { type: 'object', properties: { - isStrict: { type: 'boolean' }, + isStrict: { + type: 'boolean', + }, }, }, ], }, defaultOptions: [ { - isStrict: false, + isStrict: true, }, ], - create(context, [options], helpers) { + create(context, [{ isStrict = true }], helpers) { function getStatementIdentifier(statement: TSESTree.Statement) { const callExpression = getStatementCallExpression(statement); @@ -113,7 +115,6 @@ export default createTestingLibraryRule({ function checkNoUnnecessaryActFromBlockStatement( blockStatementNode: TSESTree.BlockStatement ) { - const { isStrict } = options; const functionNode = blockStatementNode.parent as | TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression diff --git a/tests/__snapshots__/index.test.ts.snap b/tests/__snapshots__/index.test.ts.snap index 4333d287..2bee4441 100644 --- a/tests/__snapshots__/index.test.ts.snap +++ b/tests/__snapshots__/index.test.ts.snap @@ -58,12 +58,7 @@ Object { "testing-library/no-node-access": "error", "testing-library/no-promise-in-fire-event": "error", "testing-library/no-render-in-setup": "error", - "testing-library/no-unnecessary-act": Array [ - "error", - Object { - "isStrict": true, - }, - ], + "testing-library/no-unnecessary-act": "error", "testing-library/no-wait-for-empty-callback": "error", "testing-library/no-wait-for-multiple-assertions": "error", "testing-library/prefer-find-by": "error", diff --git a/tests/lib/rules/no-unnecessary-act.test.ts b/tests/lib/rules/no-unnecessary-act.test.ts index 0a372f3f..c07344a6 100644 --- a/tests/lib/rules/no-unnecessary-act.test.ts +++ b/tests/lib/rules/no-unnecessary-act.test.ts @@ -13,15 +13,18 @@ type ValidTestCase = TSESLint.ValidTestCase; type InvalidTestCase = TSESLint.InvalidTestCase; type TestCase = InvalidTestCase | ValidTestCase; -const enableStrict = (array: T[]): T[] => +const addOptions = ( + array: T[], + options?: Options[number] +): T[] => array.map((testCase) => ({ ...testCase, - options: [ - { - isStrict: true, - }, - ], + options: [options], })); +const disableStrict = (array: T[]): T[] => + addOptions(array, { isStrict: false }); +const enableStrict = (array: T[]): T[] => + addOptions(array, { isStrict: true }); /** * - AGR stands for Aggressive Reporting @@ -886,12 +889,12 @@ const invalidTestCases: InvalidTestCase[] = [ ruleTester.run(RULE_NAME, rule, { valid: [ ...validTestCases, - ...validNonStrictTestCases, + ...disableStrict(validNonStrictTestCases), ...enableStrict(validTestCases), ], invalid: [ ...invalidTestCases, - ...invalidStrictTestCases, + ...disableStrict(invalidStrictTestCases), ...enableStrict(invalidTestCases), ], });