From ffefeaeb3c373e8e7dfb6b539e03f71d98620d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Verit=C3=A9=20Mugabo?= Date: Wed, 14 Aug 2024 20:52:26 -0400 Subject: [PATCH] fix(expect-expect): make assert work well with expect-expect (#508) --- src/rules/expect-expect.ts | 16 ++++++---------- tests/expect-expect.test.ts | 9 +++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/rules/expect-expect.ts b/src/rules/expect-expect.ts index 66556ae..7ad7891 100644 --- a/src/rules/expect-expect.ts +++ b/src/rules/expect-expect.ts @@ -60,7 +60,7 @@ export default createEslintRule({ noAssertions: 'Test has no assertions' } }, - defaultOptions: [{ assertFunctionNames: ['expect'], additionalTestBlockFunctions: [] }], + defaultOptions: [{ assertFunctionNames: ['expect', 'assert'], additionalTestBlockFunctions: [] }], create(context, [{ assertFunctionNames = ['expect'], additionalTestBlockFunctions = [] }]) { const unchecked: TSESTree.CallExpression[] = [] const settings = parsePluginSettings(context.settings) @@ -108,16 +108,12 @@ export default createEslintRule({ } }, 'Program:exit'() { - const isActuallyNotValid = unchecked.filter((node) => node.arguments.some((arg) => - (arg.type === AST_NODE_TYPES.Literal && arg.value === "assert"))) - - if (!isActuallyNotValid.length) - unchecked.forEach((node) => { - context.report({ - node: node.callee, - messageId: 'noAssertions' - }) + unchecked.forEach((node) => { + context.report({ + node: node.callee, + messageId: 'noAssertions' }) + }) } } } diff --git a/tests/expect-expect.test.ts b/tests/expect-expect.test.ts index 12be0fc..343e5b1 100644 --- a/tests/expect-expect.test.ts +++ b/tests/expect-expect.test.ts @@ -15,6 +15,15 @@ ruleTester.run(RULE_NAME, rule, { `test('assert', () => { assert('foo' !== 'bar', 'foo should not be equal to bar') })`, + `test('cleanPrCommitTitle', () => { + const clean = 'Something done'; + assert.equal(cleanPrCommitTitle('Something done (#123)', 123), clean); + assert.equal(cleanPrCommitTitle(' Something done (#123) ', 123), clean); + assert.equal(cleanPrCommitTitle(' Something done ', 123), clean); + + assert.notEqual(cleanPrCommitTitle('Something done (fixes #123)', 123), clean); + assert.notEqual(cleanPrCommitTitle('Something done (#23454)', 123), clean); +});` ], invalid: [ {