Skip to content

Commit e976dd7

Browse files
committed
feat(no-unnecessary-act): make isStrict option true by default
BREAKING CHANGE: `isStrict` option is now `true` by default
1 parent cf78530 commit e976dd7

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

lib/configs/react.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export = {
1313
'testing-library/no-dom-import': ['error', 'react'],
1414
'testing-library/no-node-access': 'error',
1515
'testing-library/no-promise-in-fire-event': 'error',
16-
'testing-library/no-unnecessary-act': ['error', { isStrict: true }],
16+
'testing-library/no-unnecessary-act': 'error',
1717
'testing-library/no-wait-for-empty-callback': 'error',
1818
'testing-library/prefer-find-by': 'error',
1919
'testing-library/prefer-screen-queries': 'error',

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

tests/__snapshots__/index.test.ts.snap

+1-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@ Object {
5454
],
5555
"testing-library/no-node-access": "error",
5656
"testing-library/no-promise-in-fire-event": "error",
57-
"testing-library/no-unnecessary-act": Array [
58-
"error",
59-
Object {
60-
"isStrict": true,
61-
},
62-
],
57+
"testing-library/no-unnecessary-act": "error",
6358
"testing-library/no-wait-for-empty-callback": "error",
6459
"testing-library/prefer-find-by": "error",
6560
"testing-library/prefer-screen-queries": "error",

tests/lib/rules/no-unnecessary-act.test.ts

+11-8
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
@@ -886,12 +889,12 @@ const invalidTestCases: InvalidTestCase[] = [
886889
ruleTester.run(RULE_NAME, rule, {
887890
valid: [
888891
...validTestCases,
889-
...validNonStrictTestCases,
892+
...disableStrict(validNonStrictTestCases),
890893
...enableStrict(validTestCases),
891894
],
892895
invalid: [
893896
...invalidTestCases,
894-
...invalidStrictTestCases,
897+
...disableStrict(invalidStrictTestCases),
895898
...enableStrict(invalidTestCases),
896899
],
897900
});

0 commit comments

Comments
 (0)