Skip to content

Commit 654d8c2

Browse files
committed
refactor(cli): test fixtures for shadow DOM
Updates test fixtures to correctly retrieve the host element for components using Shadow DOM. This change ensures that tests targeting shadow DOM elements are properly scoped and that the correct component instance is being referenced. It also adds the `contains: true` property to the `assertText` calls so tests can more accurately assert against rendered text.
1 parent 8143035 commit 654d8c2

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

app-min/test__if_not_no-unit-tests/my-app.spec.ext

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ describe('my-app', () => {
2929
}
3030
// @endif
3131
// @if !tailwindcss
32-
assertText('Hello World!', { compact: true });
32+
assertText('Hello World!', { compact: true, contains: true });
3333
// @endif
3434
});
3535

3636
// @if shadow-dom
3737
it('applies shared Shadow DOM styles to internal elements', async () => {
38-
const { host } = await createFixture('<my-app></my-app>', {}, [MyApp]).started;
38+
const { appHost: host } = await createFixture('<my-app></my-app>', {}, [MyApp]).started;
3939

4040
// Locate element rendered inside the component's own shadow root
4141
const sharedStyledEl = host.shadowRoot?.querySelector('.shared-shadow-style');
@@ -48,8 +48,8 @@ describe('my-app', () => {
4848

4949
it('ensures CSS isolation between Shadow DOM components', async () => {
5050
// Create two instances of the component
51-
const { host: host1 } = await createFixture('<my-app></my-app>', {}, [MyApp]).started;
52-
const { host: host2 } = await createFixture('<my-app></my-app>', {}, [MyApp]).started;
51+
const { appHost: host1 } = await createFixture('<my-app></my-app>', {}, [MyApp]).started;
52+
const { appHost: host2 } = await createFixture('<my-app></my-app>', {}, [MyApp]).started;
5353

5454
// Verify both components have their own shadow roots
5555
expect(host1.shadowRoot).not.toBeNull();

plugin-min/src/hello-world.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
<h1 class="hello-world">Hello World! ${message}</h1>
2+
<!-- @if shadow-dom -->
3+
<div class="shadow-demo-section">
4+
<div class="shared-shadow-style">
5+
<div class="shared-shadow-text">This content uses shared Shadow DOM styles!</div>
6+
</div>
7+
<div class="shadow-demo-border">
8+
<div>Plugin component with Shadow DOM isolation</div>
9+
</div>
10+
</div>
11+
<!-- @endif -->

plugin-min/test__if_not_no-unit-tests/hello-world.spec.ext

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ describe('my-app', () => {
1212
[HelloWorld],
1313
).started;
1414

15-
assertText('Hello World! foo', { compact: true });
15+
assertText('Hello World!', { compact: true, contains: true });
1616
});
1717

1818
// @if shadow-dom
1919
it('applies shared Shadow DOM styles to internal elements', async () => {
20-
const { host } = await createFixture(
20+
const { appHost: host } = await createFixture(
2121
'<hello-world message="test"></hello-world>',
2222
{ message: "test" },
2323
[HelloWorld],
@@ -34,12 +34,12 @@ describe('my-app', () => {
3434

3535
it('ensures CSS isolation between Shadow DOM components', async () => {
3636
// Create two instances of the component
37-
const { host: host1 } = await createFixture(
37+
const { appHost: host1 } = await createFixture(
3838
'<hello-world message="test1"></hello-world>',
3939
{ message: "test1" },
4040
[HelloWorld],
4141
).started;
42-
const { host: host2 } = await createFixture(
42+
const { appHost: host2 } = await createFixture(
4343
'<hello-world message="test2"></hello-world>',
4444
{ message: "test2" },
4545
[HelloWorld],

0 commit comments

Comments
 (0)