Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Even though we call
.focus
on elements in these 2 tests, thefocusin
event might not be fired.How to reproduce it?
Disclaimer: the CI suddenly constantly fails on this, and I have no idea why, specifically why it worked until now and suddenly doesn't anymore.
To reproduce that issue, run the tests locally through
npx serve
(thus browser context) with a20x CPU slowdown
throttling. Refresh the tests page, and click outside it before these tests run.Adding logs reveal that, even though the
document.activeElement
gets properly updated to the focused element, thefocusin
event won't fire, until the window gets focused back (clicking inside it).I guess that's an expected browser-UX feature, where the browser waits for the user to actually focus the element (thus focus the browser window first) before notifying it.
The issue here is that we don't really know how things work when running headless through
mocha-chrome
, but I'm thinking this could explain why the pipeline fails.Suggested solution
The suggested solution here simply doubles the
focusin
event by manually triggering it withhtmx.trigger
.This doesn't change the test as, what we're testing is not the
focusin
event itself being fired (that's the browser's job), just ensuring that htmx behaves correctly once that event has been fired.Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded