Closed tkeiner closed 1 month ago
Hi @tkeiner, I think the root cause of this issue is that the JSDOM environment has some constraints which are preventing the UI5 Web Components to boot properly. You can try to await the definition of the UI5 Web Components in your test before interacting with them, but this will result in a CSS parsing error because JSDOM is using an CSS parser which has not been maintained for years anymore:
await customElements.whenDefined('ui5-toast');
As an alternative, you could try using happy-dom or use a testing framework which runs in the browser like cypress or playwright.
Thanks for your feedback @MarcusNotheis, I was able to resolve the Issue by using the Toast Component directly.
Issue solved
Describe the bug
When using the useShowToast hook with Modals, the toast is displayed correctly. However, when vitest is used to run tests on the component, a type error occurs and tests are failing because of this.
Isolated Example
https://stackblitz.com/edit/github-u6ufad?file=src%2FApp.test.tsx
Reproduction steps
Or go to StackBlitz example
npm run test
Expected Behaviour
Should not throw an TypeErrors
Screenshots or Videos
No response
UI5 Web Components for React Version
1.29.0
UI5 Web Components Version
1.24.0
Browser
Chrome
Operating System
MacOS
Additional Context
As shown in the log output the error is thrown here.
I was able to fix the error by using a same structure as for the other Modal Components like this:
Or maybe just a ts-ignore is needed
Relevant log output
Organization
SAP
Declaration