Repository navigation
JS unit tests: update popover matcher - #54168
Conversation
|
Size Change: 0 B Total Size: 1.52 MB ℹ️ View Unchanged
|
|
Flaky tests detected in e71b618. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6091438030
|
Mamaduka
left a comment
There was a problem hiding this comment.
The change here makes sense to me 👍
Unfortunately, I was able reproduce the snapshot failure when running tests 20+ times.
Nooo! I thought I was special :( |
Yeah, I could reproduce it by running the tests just once 🙂 This PR is a nice refactoring, but it won't have influence on that bug. The bug is caused by the fact that the popover appearance is animated. In a rAF loop, the opacity goes from 0 to 1, and other properties like We used to have plans to add the |
jsnajdr
left a comment
There was a problem hiding this comment.
When introducing these wrappers a year ago with @tyxla, we had good reasons why they need to be separate. I would have to find the exact PRs where these discussions happened to know the details. But apparently these reasons disappeared over time, as this PR works perfectly fine.
| */ | ||
| function toBePositionedPopover( element ) { | ||
| const pass = element.classList.contains( 'is-positioned' ); | ||
| const popover = element.closest( '.components-popover' ) || element; |
There was a problem hiding this comment.
There should be no need to default to element. If the element or its ancestor doesn't have the .components-popover class, the check should immediately fail because no popover to check has been found. There's no point checking whether a non-popover element has also the .is-positioned class.
There was a problem hiding this comment.
Also, it would be nice if the matcher detected that the element is either null or not inside a Popover, and printed a nice message. At this moment it's just a TypeError:
TypeError: Cannot read properties of null (reading 'closest')
TypeError: Cannot read properties of null (reading 'classList')
I think we had that at one moment in the past, somehow it got lost.
There was a problem hiding this comment.
Thanks for the tips and context here. Much appreciated 🙇🏻
Updated accordingly.
Thanks for testing @Mamaduka and @jsnajdr - also for the explainer. I'm not sure if it's my hardware, but it also took me 20+ times to fail. I though 10 was the magic number 😄 I wonder if mocking
Good to know. I've updated the PR to return more meaningful messages as per @jsnajdr's advice. If folks are okay with the refactor I'll merge, otherwise happy to just kill the PR mercifully. |
jsnajdr
left a comment
There was a problem hiding this comment.
Although it doesn't fix any flaky test, this is still a valuable code refactoring 👍 I posted some style nits, otherwise LGTM.
| const popover = element && element.closest( '.components-popover' ); | ||
| const isPopoverPositioned = | ||
| popover && popover.classList.contains( 'is-positioned' ); | ||
| const pass = !! popover && !! isPopoverPositioned; |
There was a problem hiding this comment.
Some style nits:
- can use
element?.closestandpopover?.classListoptional chainings passcan be simply!! isPopoverPositioned, the!! popovercondition is redundant.
…rapping `getWrappingPopoverElement()`, so this commit just moves `getWrappingPopoverElement` logic into `toBePositionedPopover` to save everyone the trouble.
…element - change messaging based on error type
f1cf806 to
e71b618
Compare
What?
This PR moves
getWrappingPopoverElementlogic intotoBePositionedPopover.This PR was originally designed to fix the flaky test in
packages/nux/src/components/dot-tip/test/index.js, which usedtoBePositionedPopoverwithout a correspondinggetWrappingPopoverElement.Why?
There was no use of the
toBePositionedPopover()matcher without a wrappinggetWrappingPopoverElement().The alternative to this PR is to just wrap the flaky test assertion in a custom
getWrappingPopoverElement().Testing Instructions
CI tests should pass
To make sure the
packages/nux/src/components/dot-tip/test/index.jstests pass, in your console, run: