cypress-plugin-tab
cypress-plugin-tab copied to clipboard
Does not work properly if test browser has focus?
Hi!
I created few tests for @valu/focus-trap using this. Unfortunately it seems that it does not work quite right if tests are executed with window focus.
Steps to reproduce:
git clone [email protected]:valu-digital/focus-trap.git
cd focus-trap/
git checkout 82863d8024d1d061de8d5a0a200babb8293d8739
npm ci
Start server in another shell
npm run examples-dev
Open Cypress
npm run cypress
Hit "Run all specs" and observe how bunch of the tests fail.

Next open cypress/integration/focus-trap.spec.ts and edit some test name and hit save, live reload should trigger test rerunning and now observe how all tests pass.

I'm sometimes able to make tests pass when pressing this re-run button

but not always. Not sure why. The live reload is the only way I'm able make them pass consistently.
Any ideas what might be going on?
@valu/focus-trap works by tapping into the focusin event, calls stopImmediatePropagation() on it and programmatically focuses elements it wants with .focus(). The most relevant code here is here
https://github.com/valu-digital/focus-trap/blob/82863d8024d1d061de8d5a0a200babb8293d8739/src/index.ts#L283
Anyway thank you for creating this! This is the only tool I've been able to create any tests for library like this. Cheers!
@epeli awesome, thanks for the reproducible. I'll take a look
Any updates on this? I'm facing this too :/