webcomponents / polyfills

Web Components Polyfills
BSD 3-Clause "New" or "Revised" License
1.14k stars 165 forks source link

JEST stopped working with version 2.3.0 #222

Open LucaMele opened 4 years ago

LucaMele commented 4 years ago

https://github.com/axa-ch/patterns-library/issues/1452

https://github.com/axa-ch/jest-test-plib-v2/pull/2

AndyOGo commented 4 years ago

Since 2.3.0 Jest throws TypeError: The custom element constructor's prototype is not an object.:

From my insights it seems that two different Object constructors are being used, which causes this check to fail. https://github.com/webcomponents/polyfills/blob/75717f84bbb6ba165dacbf6c406da5845bcb9664/packages/custom-elements/src/CustomElementRegistry.js#L168-L173

Reproduction Repo with relevant analysis in PR description: https://github.com/axa-ch/jest-test-plib-v2/pull/1

Lock down to 2.2.10 to mitigate this type error: https://github.com/axa-ch/jest-test-plib-v2/pull/2

tomstumshais commented 4 years ago

Hey! Any progress with this issue?

peabnuts123 commented 4 years ago

If you are using @webcomponents/custom-elements lock down to version ^1.2.4

elisiondan commented 3 years ago

If you don't actually need the customElements to return an actual element and you're only aiming to avoid this error, you can can mock the implementation.

Create a config file for jest that will be included in all tests as part of a setupFiles option.

setup-globals.js
window.customElements = {
  define: () => {},
};
// jest.config.js
  ....
  setupFiles: [
    '<rootDir>/YOUR-PATH/setup-globals.js',
  ],
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.