Skip to content

Commit

Permalink
fix(expect-expect): make assert work well with expect-expect (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
veritem committed Aug 15, 2024
1 parent 6ff987b commit ffefeae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/rules/expect-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
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)
Expand Down Expand Up @@ -108,16 +108,12 @@ export default createEslintRule<Options, MESSAGE_ID>({
}
},
'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'
})
})
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/expect-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down

0 comments on commit ffefeae

Please sign in to comment.