Skip to content

Commit

Permalink
feat(no-unnecessary-act): make isStrict option true by default (#479
Browse files Browse the repository at this point in the history
)
  • Loading branch information
MichaelDeBoey committed Oct 14, 2021
1 parent ea893cc commit e3ebef8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/configs/react.ts
Expand Up @@ -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/no-wait-for-side-effects': 'error',
Expand Down
11 changes: 6 additions & 5 deletions lib/rules/no-unnecessary-act.ts
Expand Up @@ -27,7 +27,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
recommendedConfig: {
dom: false,
angular: false,
react: ['error', { isStrict: true }],
react: 'error',
vue: false,
},
},
Expand All @@ -40,18 +40,20 @@ export default createTestingLibraryRule<Options, MessageIds>({
{
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);

Expand Down Expand Up @@ -113,7 +115,6 @@ export default createTestingLibraryRule<Options, MessageIds>({
function checkNoUnnecessaryActFromBlockStatement(
blockStatementNode: TSESTree.BlockStatement
) {
const { isStrict } = options;
const functionNode = blockStatementNode.parent as
| TSESTree.ArrowFunctionExpression
| TSESTree.FunctionExpression
Expand Down
7 changes: 1 addition & 6 deletions tests/__snapshots__/index.test.ts.snap
Expand Up @@ -66,12 +66,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/no-wait-for-side-effects": "error",
Expand Down
28 changes: 13 additions & 15 deletions tests/lib/rules/no-unnecessary-act.test.ts
Expand Up @@ -13,15 +13,18 @@ type ValidTestCase = TSESLint.ValidTestCase<Options>;
type InvalidTestCase = TSESLint.InvalidTestCase<MessageIds, Options>;
type TestCase = InvalidTestCase | ValidTestCase;

const enableStrict = <T extends TestCase>(array: T[]): T[] =>
const addOptions = <T extends TestCase>(
array: T[],
options?: Options[number]
): T[] =>
array.map((testCase) => ({
...testCase,
options: [
{
isStrict: true,
},
],
options: [options],
}));
const disableStrict = <T extends TestCase>(array: T[]): T[] =>
addOptions(array, { isStrict: false });
const enableStrict = <T extends TestCase>(array: T[]): T[] =>
addOptions(array, { isStrict: true });

/**
* - AGR stands for Aggressive Reporting
Expand Down Expand Up @@ -208,11 +211,6 @@ const validTestCases: ValidTestCase[] = [

const invalidStrictTestCases: InvalidTestCase[] = [
{
options: [
{
isStrict: true,
},
],
code: `// case: RTL act wrapping both RTL and non-RTL calls with strict option
import { act, render } from '@testing-library/react'
Expand Down Expand Up @@ -886,12 +884,12 @@ const invalidTestCases: InvalidTestCase[] = [
ruleTester.run(RULE_NAME, rule, {
valid: [
...validTestCases,
...validNonStrictTestCases,
...enableStrict(validTestCases),
...disableStrict(validNonStrictTestCases),
...disableStrict(validTestCases),
],
invalid: [
...invalidTestCases,
...invalidStrictTestCases,
...enableStrict(invalidTestCases),
...enableStrict(invalidStrictTestCases),
...disableStrict(invalidTestCases),
],
});

0 comments on commit e3ebef8

Please sign in to comment.