Skip to content

Commit

Permalink
fix(prefer-user-event): prevent crash with custom createEvent function (
Browse files Browse the repository at this point in the history
#422) (#422)

Closes #405

Co-authored-by: Mario Beltrán Alarcón <belco90@gmail.com>
  • Loading branch information
gndelia and Belco90 committed Jul 20, 2021
1 parent 5dff88e commit 4808bca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/prefer-user-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
ASTUtils.isIdentifier(node.init.callee.property)
) {
fireEventMethodName = node.init.callee.property.name;
} else {
} else if (node.init.arguments.length > 0) {
fireEventMethodName = (node.init.arguments[0] as TSESTree.Literal)
.value as string;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/prefer-user-event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ ruleTester.run(RULE_NAME, rule, {
fireEventAliased(node, event)
`,
},
{
code: `
const createEvent = () => 'Event';
const event = createEvent();
`,
},
],
invalid: [
...createScenarioWithImport<TSESLint.InvalidTestCase<MessageIds, Options>>(
Expand Down

0 comments on commit 4808bca

Please sign in to comment.