Skip to content

Commit e3ebef8

Browse files
feat(no-unnecessary-act): make isStrict option true by default (#479)
1 parent ea893cc commit e3ebef8

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

Diff for: lib/configs/react.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export = {
1414
'testing-library/no-node-access': 'error',
1515
'testing-library/no-promise-in-fire-event': 'error',
1616
'testing-library/no-render-in-setup': 'error',
17-
'testing-library/no-unnecessary-act': ['error', { isStrict: true }],
17+
'testing-library/no-unnecessary-act': 'error',
1818
'testing-library/no-wait-for-empty-callback': 'error',
1919
'testing-library/no-wait-for-multiple-assertions': 'error',
2020
'testing-library/no-wait-for-side-effects': 'error',

Diff for: lib/rules/no-unnecessary-act.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
2727
recommendedConfig: {
2828
dom: false,
2929
angular: false,
30-
react: ['error', { isStrict: true }],
30+
react: 'error',
3131
vue: false,
3232
},
3333
},
@@ -40,18 +40,20 @@ export default createTestingLibraryRule<Options, MessageIds>({
4040
{
4141
type: 'object',
4242
properties: {
43-
isStrict: { type: 'boolean' },
43+
isStrict: {
44+
type: 'boolean',
45+
},
4446
},
4547
},
4648
],
4749
},
4850
defaultOptions: [
4951
{
50-
isStrict: false,
52+
isStrict: true,
5153
},
5254
],
5355

54-
create(context, [options], helpers) {
56+
create(context, [{ isStrict = true }], helpers) {
5557
function getStatementIdentifier(statement: TSESTree.Statement) {
5658
const callExpression = getStatementCallExpression(statement);
5759

@@ -113,7 +115,6 @@ export default createTestingLibraryRule<Options, MessageIds>({
113115
function checkNoUnnecessaryActFromBlockStatement(
114116
blockStatementNode: TSESTree.BlockStatement
115117
) {
116-
const { isStrict } = options;
117118
const functionNode = blockStatementNode.parent as
118119
| TSESTree.ArrowFunctionExpression
119120
| TSESTree.FunctionExpression

Diff for: tests/__snapshots__/index.test.ts.snap

+1-6
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,7 @@ Object {
6666
"testing-library/no-node-access": "error",
6767
"testing-library/no-promise-in-fire-event": "error",
6868
"testing-library/no-render-in-setup": "error",
69-
"testing-library/no-unnecessary-act": Array [
70-
"error",
71-
Object {
72-
"isStrict": true,
73-
},
74-
],
69+
"testing-library/no-unnecessary-act": "error",
7570
"testing-library/no-wait-for-empty-callback": "error",
7671
"testing-library/no-wait-for-multiple-assertions": "error",
7772
"testing-library/no-wait-for-side-effects": "error",

Diff for: tests/lib/rules/no-unnecessary-act.test.ts

+13-15
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ type ValidTestCase = TSESLint.ValidTestCase<Options>;
1313
type InvalidTestCase = TSESLint.InvalidTestCase<MessageIds, Options>;
1414
type TestCase = InvalidTestCase | ValidTestCase;
1515

16-
const enableStrict = <T extends TestCase>(array: T[]): T[] =>
16+
const addOptions = <T extends TestCase>(
17+
array: T[],
18+
options?: Options[number]
19+
): T[] =>
1720
array.map((testCase) => ({
1821
...testCase,
19-
options: [
20-
{
21-
isStrict: true,
22-
},
23-
],
22+
options: [options],
2423
}));
24+
const disableStrict = <T extends TestCase>(array: T[]): T[] =>
25+
addOptions(array, { isStrict: false });
26+
const enableStrict = <T extends TestCase>(array: T[]): T[] =>
27+
addOptions(array, { isStrict: true });
2528

2629
/**
2730
* - AGR stands for Aggressive Reporting
@@ -208,11 +211,6 @@ const validTestCases: ValidTestCase[] = [
208211

209212
const invalidStrictTestCases: InvalidTestCase[] = [
210213
{
211-
options: [
212-
{
213-
isStrict: true,
214-
},
215-
],
216214
code: `// case: RTL act wrapping both RTL and non-RTL calls with strict option
217215
import { act, render } from '@testing-library/react'
218216
@@ -886,12 +884,12 @@ const invalidTestCases: InvalidTestCase[] = [
886884
ruleTester.run(RULE_NAME, rule, {
887885
valid: [
888886
...validTestCases,
889-
...validNonStrictTestCases,
890-
...enableStrict(validTestCases),
887+
...disableStrict(validNonStrictTestCases),
888+
...disableStrict(validTestCases),
891889
],
892890
invalid: [
893891
...invalidTestCases,
894-
...invalidStrictTestCases,
895-
...enableStrict(invalidTestCases),
892+
...enableStrict(invalidStrictTestCases),
893+
...disableStrict(invalidTestCases),
896894
],
897895
});

0 commit comments

Comments
 (0)