Skip to content

Jest: SyntaxError: Cannot use import statement outside a module #7269

Answered by Lukas742
philippkolbe asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @philippkolbe

testing (ui5) web components with JSDOM is generally discouraged mainly because:

  • JSDOM is a node DOM emulator, not a full browser: It lacks many browser APIs (e.g., ResizeObserver, IntersectionObserver, matchMedia), requiring manual polyfills or mocks for testing web components.
  • No layout engine or full CSSOM support: JSDOM doesn't perform rendering or style computations, so methods like getBoundingClientRect and media queries won't function as expected.
  • Incomplete Shadow DOM and Custom Elements support: Features like slotting and event retargeting are only partially implemented, leading to unreliable tests for encapsulation and component behavior.

For accurate and reli…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@philippkolbe
Comment options

@philippkolbe
Comment options

@Lukas742
Comment options

Answer selected by philippkolbe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants