Skip to content

Commit

Permalink
feat(no-unnecessary-act): make isStrict option true by default
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `isStrict` option is now `true` by default
  • Loading branch information
MichaelDeBoey committed Oct 13, 2021
1 parent db42e69 commit fe6f6a5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
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/prefer-find-by': '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 @@ -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",
Expand Down
19 changes: 11 additions & 8 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 @@ -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),
],
});

0 comments on commit fe6f6a5

Please sign in to comment.