Skip to content

feat(no-unnecessary-act): make isStrict option true by default #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/configs/react.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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),
],
});