Repository navigation
test(components/molecule/select): fix flaky onblur test - #2397
Conversation
|
|
|
||
| // Then | ||
| sinon.assert.calledOnce(spy) | ||
| sinon.assert.called(spy) |
There was a problem hiding this comment.
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.
Good catch! will update this. Thanks! (:
| userEvents.click(textBox) | ||
| userEvents.tab() | ||
| fireEvent.focusIn(textBox) | ||
| fireEvent.focusOut(textBox) |
There was a problem hiding this comment.
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.
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.
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.
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 firingfocusInandfocusOuteventsScreenshots - Animations