ealush / emoji-picker-react

The most popular React Emoji Picker
https://ealush.com/emoji-picker-react/
MIT License
991 stars 166 forks source link

Unit tests failing as of 4.9.1 #407

Open skrivle opened 4 months ago

skrivle commented 4 months ago

Hi πŸ‘‹

First of all, thank you so much for the great work on emoji-picker-react πŸ™ .

I wanted to report that we saw our unit tests fail when upgrading to 4.9.2. We believe the breaking change was introduced as part of 4.9.1. More specifically in the getLabelHight function here

Since the DEFAULT_LABEL_HEIGHT is now returned whenever no height greater than 0 is found, the function will always return 40 when running inside JSDOM. All other measurements (getBoundingClientRect, getBoundingClientRect, ...), however will return 0. This makes it so that no emoji is found when calling focusFirstVisibleEmoji.

We have a test that does something along these lines:

const searchBox = screen.getByRole('textbox', { name: 'Type to search for an emoji' });

await userEvent.type(searchBox, 'cat');
await userEvent.tab();
await userEvent.tab();
await userEvent.tab();
await userEvent.keyboard('{enter}');

expect(update).toHaveBeenCalledWIth(...)

We've currently fixed this by mocking getBoundingClientRect and getBoundingClientRect to return values in way so that focusFirstVisibleEmoji does return results. However, this is not very transparant and might easily break if the underlying implementation changes.

Though this is an issue that will only occur when running in JSDOM, I think more folks might run into this, so if there's a way to change the implementation to accommodate this, that'd be really great!

Thanks again for you work.

Regards,

Jelle