-
Notifications
You must be signed in to change notification settings - Fork 797
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
bug: testing Stencil lib within external project with Jest not working since shadowDomShim was removed #5262
Comments
Hey @zerock54 👋 Thanks for the report! I'm currently seeing the following error when I run the steps in the README file of the reproduction case:
I don't think this is the error you're seeing, based on the context of this issue report. Can you please confirm/not if this is what you're seeing? |
Hey @rwaskiewicz, Sorry about that I just sent a fix Thanks :) |
Thanks! I'm now seeing the following error, which I think matches a little more closely with the issue you reported:
Since Stencil is no longer shimming the Shadow DOM, it appears that testing-library does not know how to "pierce" or read into our web components. Full Disclosure: I'm far from a testing-library expert and haven't used it myself. As I understand it, testing-library itself doesn't support the Shadow DOM at this time (testing-library/dom-testing-library#413). There does however, appear to be a library that can help bridge the gap here - https://github.com/KonnorRogers/shadow-dom-testing-library/tree/main I was able to get your reproduction case working with import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
-import { render, screen, waitFor } from '@testing-library/angular';
+import { render, waitFor } from '@testing-library/angular';
+import { screen } from "shadow-dom-testing-library";
describe('AppComponent', () => {
const setup = async (): Promise<{
@@ -20,7 +21,7 @@ describe('AppComponent', () => {
await waitFor(
() => {
- expect(screen.getByText("Hello, World! I'm nicolas")).toBeInTheDocument();
+ expect(screen.getByShadowText("Hello, World! I'm nicolas")).toBeInTheDocument();
},
{ timeout: 10000 }
); Let me know if that works for your use case! |
Hi @rwaskiewicz, I tested it and it looks to work great. I completely missed this lib during my first investigations... Thank you for your time ! |
Prerequisites
Stencil Version
4
Current Behavior
Hi,
I have an app which uses a Stencil library as a Design System.
This app is tested with Jest and testing-library.
I was using the shadowDomShim extra config to make the shadow DOM available within Jest but, since this field is now gone, the content of my components configured with {shadow: true} is empty
Expected Behavior
The shadow dom appears as normal within Jest
System Info
No response
Steps to Reproduce
npm --prefix ./stencil-jest install && npm --prefix ./bug-stencil-jest install
stencil-jest
, runnpm run build
stencil-jest
, runnpm link
bug-stencil-jest
, runnpm link stencil-jest
bug-stencil-jest
, runnpm run test
Code Reproduction URL
https://github.com/zerock54/stencil-jest-shadow-dom/tree/main
Additional Information
Everything was fine with Stencil 3 by setting
__deprecated__shadowDomShim: true
Is there a way to make it work the same way now that this config is gone in Stencil 4 ?
Thanks
The text was updated successfully, but these errors were encountered: