-
Notifications
You must be signed in to change notification settings - Fork 767
/
deep-selector.e2e.ts
72 lines (61 loc) · 2.77 KB
/
deep-selector.e2e.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { newE2EPage } from '@stencil/core/testing';
describe('Shadow DOM piercing', () => {
it('can pierce through shadow DOM via Puppeteer primitives', async () => {
// create a new puppeteer page
const page = await newE2EPage({
html: `
<cmp-a></cmp-a>
`,
});
const spanCmpA = await page.$('cmp-a >>> span');
expect(await spanCmpA.evaluate((el) => el.textContent)).toBe('I am in component A');
const spanCmpB = await page.$('cmp-a >>> cmp-b >>> span');
expect(await spanCmpB.evaluate((el) => el.textContent)).toBe('I am in component B');
const spanCmpC = await page.$('cmp-a >>> cmp-b >>> cmp-c >>> span');
expect(await spanCmpC.evaluate((el) => el.textContent)).toBe('I am in component C');
// we skip through the shadow dom
const spanCmp = await page.$('cmp-a >>> cmp-c >>> span');
expect(await spanCmp.evaluate((el) => el.textContent)).toBe('I am in component C');
});
it('can pierce through shadow DOM via Stencil E2E testing API', async () => {
// create a new puppeteer page
const page = await newE2EPage({
html: `
<cmp-a></cmp-a>
`,
});
const spanCmpA = await page.find('cmp-a >>> span');
expect(spanCmpA.textContent).toBe('I am in component A');
const spanCmpB = await page.find('cmp-a >>> cmp-b >>> span');
expect(spanCmpB.textContent).toBe('I am in component B');
const spanCmpC = await page.find('cmp-a >>> div > cmp-b >>> div cmp-c >>> span');
expect(spanCmpC.textContent).toBe('I am in component C');
// we skip through the shadow dom
const spanCmp = await page.find('cmp-a >>> cmp-c >>> span');
expect(spanCmp.textContent).toBe('I am in component C');
});
it('can pierce through shadow DOM via findAll', async () => {
// create a new puppeteer page
const page = await newE2EPage({
html: `
<cmp-a></cmp-a>
`,
});
const spans = await page.findAll('cmp-a >>> span');
expect(spans).toHaveLength(3);
expect(spans[0].textContent).toBe('I am in component A');
expect(spans[1].textContent).toBe('I am in component B');
expect(spans[2].textContent).toBe('I am in component C');
const spansCmpB = await page.findAll('cmp-a >>> cmp-b >>> span');
expect(spansCmpB).toHaveLength(2);
expect(spansCmpB[0].textContent).toBe('I am in component B');
expect(spansCmpB[1].textContent).toBe('I am in component C');
const spansCmpC = await page.findAll('cmp-a >>> cmp-b >>> cmp-c >>> span');
expect(spansCmpC).toHaveLength(1);
expect(spansCmpC[0].textContent).toBe('I am in component C');
// we skip through the shadow dom
const spansCmp = await page.findAll('cmp-a >>> cmp-c >>> span');
expect(spansCmp).toHaveLength(1);
expect(spansCmp[0].textContent).toBe('I am in component C');
});
});