-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(await-async-events): instance of userEvent is recognized as async #830
base: main
Are you sure you want to change the base?
feat(await-async-events): instance of userEvent is recognized as async #830
Conversation
89e5f97
to
f28f7e1
Compare
f28f7e1
to
8ba464f
Compare
any updates? |
@ka2jun8 Sorry for the late response! I'll review this soon. |
feat(await-async-events): added comments feat(await-async-events): better test case feat(await-async-events): edge case fixed, test added feat(await-async-events): use actual userEvent import for check, tests
8f1e313
to
636dee8
Compare
const getUserEventImportIdentifier = (node: ImportModuleNode | null) => { | ||
if (!node) { | ||
return null; | ||
} | ||
|
||
if (isImportDeclaration(node)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should always receive a node
. If the node is not available, then avoid calling this function in the corresponding code.
const getUserEventImportIdentifier = (node: ImportModuleNode | null) => { | |
if (!node) { | |
return null; | |
} | |
if (isImportDeclaration(node)) { | |
const getUserEventImportIdentifier = (node: ImportModuleNode) => { | |
if (isImportDeclaration(node)) { |
} | ||
|
||
return null; | ||
return getUserEventImportIdentifier(importedUserEventLibraryNode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you should call getUserEventImportIdentifier
only if importedUserEventLibraryNode
exists.
if ( | ||
token.type === 'Identifier' && | ||
token.value === userEventImport.name && | ||
tokensAndComments[index + 1].value === '.' && | ||
tokensAndComments[index + 2].value === 'setup' && | ||
tokensAndComments[index + 3].value === '(' && | ||
tokensAndComments[index - 1].value === '=' | ||
) { | ||
return tokensAndComments[index - 2].value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a bit brittle and hardcoded… I'm trying to think a better way to implement this in a more generic way with AST selectors.
* Finds if the userEvent is used as an instance | ||
*/ | ||
|
||
export function getUserEventInstance( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one should belong to the detect-testing-library-utils
too.
@@ -32,7 +32,7 @@ const USER_EVENT_ASYNC_FUNCTIONS = [ | |||
'upload', | |||
] as const; | |||
const FIRE_EVENT_ASYNC_FRAMEWORKS = [ | |||
'@testing-library/vue', | |||
// '@testing-library/vue', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be commented.
I gave it a first round. After the changes requested are applied, I'll give it another round. |
any updates on this please? |
@Kvanttinen Are you still interested in implementing this feature? If so, can you please rebase onto latest |
Checks
Changes
Adds a feature that events from the instance of userEvent are recognized as async events.
Example:
const user = userEvent.setup();
user.click(button);
The 'user' will be flagged in this case.
Context
Closes #812
My first open source PR, and not used to GitHub that much, so there might be some errors with the process. Changes itself are quite simple, but I didn't find a more elegant way to do that.