-
Notifications
You must be signed in to change notification settings - Fork 59
test(components/molecule/select): fix flaky onblur test #2397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
// Then | ||
sinon.assert.calledOnce(spy) | ||
sinon.assert.called(spy) |
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.
isn't calledOnce
a better choice for this kind of test? being it more specific, the test is more precise, IMHO. What do you think?
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.
Good catch! will update this. Thanks! (:
userEvents.click(textBox) | ||
userEvents.tab() | ||
fireEvent.focusIn(textBox) | ||
fireEvent.focusOut(textBox) |
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.
https://testing-library.com/docs/guide-events
have a look at this... perhaps that's why you're feeling it's a bit flaky on your local environment? π€
perhaps using imperative focus / blur is more robust:
https://testing-library.com/docs/guide-events#alternatives
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.
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.
oh that's sad... π€
as an interim solution... how do you feel about doing focus first on textBox
, as you're already doing, and then on some other element so that it hopefully fires the blur event on the textbox? I know it's a bit hacky but perhaps more robust than the original fireEvent
focus and blur.
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.
Better use click and tab, Its what user is going to tackle, dont care if it blurs or focus on his/her POV
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 agree, click
and tab
should be what we aim for, which was my original intention
userEvents.click(textBox)
userEvents.tab()
After trying quite different things, like rendering another component and clicking that component
const component = props => (
<>
<div>
<button>Hello!</button>
</div>
<Component {...props} />
</>
)
const setup = setupEnvironment(component)
I've realized that this behavior happens whether the browser that runs the tests is opened/closed. π€―
only with fireEvent.blur()
it fires the event from the node, regardless of wether the Karma browser is opened or not...
|
Merging this PR. |
Category/Component
TASK:
Types of changes
Description, Motivation and Context
Avoid weird race condition with
userEvent.tab()
by firingfocusIn
andfocusOut
eventsScreenshots - Animations