question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Please provide window.customElements to be able to test custom Web Components

See original GitHub issue

I would like to test some custom web components. Chromium supports commands like

window.customElements.define('my-custom-element', MyCustomElementClass);

to register a custom web component.

However, window.customElements does not seem to be known in the context of jest tests.

=> Please allow to test custom web components directly with jest.

Also see related SO question:

https://stackoverflow.com/questions/57478484/how-to-test-custom-web-component-with-jest/57481761#57481761

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

5reactions
SimenBcommented, Feb 17, 2020

@awdltd you’ll need to use jest-environment-jsdom-sixteen until jest@26. Still a few months out I’d guess (haven’t thought about it yet)

@mkay581 https://github.com/facebook/jest/blob/1ed46e71a058c93b529e5e3f9388a800352de21a/packages/jest-environment-jsdom/package.json#L18

3reactions
awdltdcommented, Feb 17, 2020

Hey @mkay581, I checked in my node_modules folder and jest-environment-jsdom is bundled with Jest (I admit I am taking liberties to assume that is what Jest uses by default). The package.json for this has “jsdom”: “^15.1.1”, so I assume that Jest will automatically use 15.. by default

Thanks for the heads up and the quick response, @SimenB! Fortunately found jest-environment-jsdom-sixteen in the interim and testing in that at the moment 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to test custom web component with jest? - Stack Overflow
JSDOM 16.2 includes basic support for custom elements and is available in Jest 26.5 and above. Here's a simple Jest test that shows...
Read more >
Window.customElements - Web APIs - MDN Web Docs
The customElements read-only property of the Window interface returns a reference to the CustomElementRegistry object, which can be used to ...
Read more >
Web Components Test Drive - Medium
In this tutorial, we will build a web component that can be published ... Custom elements;; Templates;; Shadow DOM; and; ES modules (until ......
Read more >
Custom Elements Everywhere
What's this? Custom Elements are the lynchpin in the Web Components specifications. They give developers the ability to define their own HTML elements....
Read more >
Custom elements - The Modern JavaScript Tutorial
We can observe attributes by providing their list in observedAttributes() static getter. For such attributes, attributeChangedCallback is called ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found