-
Notifications
You must be signed in to change notification settings - Fork 839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EuiComboBox failing in Jest environment #7505
Comments
Heya @jlove-dev! The answer to this is that you need to mock the underlying https://github.com/elastic/eui/blob/main/src/services/canvas/canvas_text_utils.testenv.ts You can import or require this file via: const { CanvasTextUtils } = require('@elastic/eui/test-env/services/canvas/canvas_text_utils'); You'll then need to set up your Jest environment with a eui/scripts/jest/setup/mocks.js Lines 18 to 24 in 1fa8cf0
Lines 36 to 40 in ce51332
|
Thank you so much @cee-chen! I really appreciate the support here and it makes sense to go about it this way. |
Absolutely, anytime!! ❤️ Thanks for taking the trouble to clearly fill out the issue template and make a reproduction repo - it made answering a breeze! |
Describe the bug
I've run into an issue where, even in a brand new CRA, EuiComboBox throws errors when trying to test with Jest. Specifically, here's what I see:
TypeError: Cannot set properties of undefined (setting 'font')
Which is coming from:
It looks like this is primarily used for the combobox, I can only find 8 files in
Elastic/eui
which mostly seem related.I've also created a reproduction repo which shows this.
Impact and severity
Medium
I haven't been able to find a workaround however it does cause any components which use EuiComboBox to not have test cases. I tried to mock HTMLCanvasElement however that didn't seem to help.
Environment and versions
To Reproduce
Reproduction Repo
^ I made this in roughly five minutes using just CRA and installing Jest. I don't believe this is a Jest issue since it only happens with this component out of EUI but I'm open to being corrected.
Expected behavior
I would expect this error to not happen. It results in any Jest test which includes EuiComboBox to fail.
Minimum reproducible sandbox
Reproduction Repo
I'm not sure how I can add Jest to sandbox, if anyone has a suggestion on that then please let me know.
The text was updated successfully, but these errors were encountered: