You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to test components with ViewEncapsulation.ShadowDom? #290
Hi, thanks for raising this issue.
Unfortunately, we don't support shadow DOM for now.
We're tracking this in DOM Testing Library, if it lands there, it should also be possible to use it with Angular Testing Library.
Hey @2YY, I had the same problem and I solved using this library (shadow-dom-testing-library), it works just fine for me.
I hope soon we are getting support from Angular Testing Library to get elements in a Shadow DOM.
As a workaround, we override the view encapsulation of our Shadow Dom components for test.
const TestSubject = overrideComponentViewEncapsulation(RealComponentWithShadowDom, ViewEncapsulation.None);
// use TestSubject instead of RealComponentWithShadowDom in the test
Here is the override function:
export function overrideComponentViewEncapsulation<ComponentType extends Type<any>>(component: ComponentType, viewEncapsulation: ViewEncapsulation): ComponentType {
const newComponentAnnotations: any = (component as any).__annotations__[0];
@Component({
...newComponentAnnotations,
encapsulation: viewEncapsulation,
} as any)
class NewComponent extends component {
}
Object.defineProperty(NewComponent, 'name', { value: component.name + 'WithViewEncapsulationOverride' });
return NewComponent;
}
Activity
timdeschryver commentedon Mar 30, 2022
Hi, thanks for raising this issue.
Unfortunately, we don't support shadow DOM for now.
We're tracking this in DOM Testing Library, if it lands there, it should also be possible to use it with Angular Testing Library.
ralfting commentedon Feb 15, 2023
Hey @2YY, I had the same problem and I solved using this library (
shadow-dom-testing-library), it works just fine for me.I hope soon we are getting support from Angular Testing Library to get elements in a Shadow DOM.
jtrentes commentedon Mar 7, 2024
Is there any news on this topic? The tracked issue in DOM testing library has not been updated since 2022.
cycleandsoak commentedon Feb 7, 2025
As a workaround, we override the view encapsulation of our Shadow Dom components for test.
Here is the override function: