Skip to content

Commit 937cca8

Browse files
chore: update lit example to use the new locators API (#6628)
Co-authored-by: Hiroshi Ogawa <[email protected]>
1 parent 946d8bb commit 937cca8

File tree

7 files changed

+61
-736
lines changed

7 files changed

+61
-736
lines changed

examples/lit/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
},
1818
"devDependencies": {
1919
"@vitest/browser": "latest",
20-
"@vitest/ui": "latest",
2120
"jsdom": "latest",
21+
"playwright": "^1.47.2",
2222
"vite": "latest",
23-
"vitest": "latest",
24-
"webdriverio": "^8.32.2"
23+
"vitest": "latest"
2524
},
2625
"stackblitz": {
2726
"startCommand": "npm run test:ui"

examples/lit/test/basic.test.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { beforeEach, describe, expect, it, vi } from 'vitest'
1+
import { beforeEach, describe, expect, it } from 'vitest'
2+
import { page } from '@vitest/browser/context'
23

34
import '../src/my-button.js'
45

@@ -7,27 +8,13 @@ describe('Button with increment', async () => {
78
document.body.innerHTML = '<my-button name="World"></my-button>'
89
})
910

10-
it('should increment the count on each click', () => {
11-
getInsideButton()?.click()
12-
expect(getInsideButton()?.textContent).toContain('1')
13-
})
11+
it('should increment the count on each click', async () => {
12+
await page.getByRole('button').click()
1413

15-
it('should show name props', () => {
16-
getInsideButton()
17-
expect(document.body.querySelector('my-button')?.shadowRoot?.innerHTML).toContain('World')
14+
await expect.element(page.getByRole('button')).toHaveTextContent('2')
1815
})
1916

20-
it('should dispatch count event on button click', () => {
21-
const spyClick = vi.fn()
22-
23-
document.querySelector('my-button')!.addEventListener('count', spyClick)
24-
25-
getInsideButton()?.click()
26-
27-
expect(spyClick).toHaveBeenCalled()
17+
it('should show name props', async () => {
18+
await expect.element(page.getByRole('heading')).toHaveTextContent('World')
2819
})
2920
})
30-
31-
function getInsideButton(): HTMLElement | null | undefined {
32-
return document.body.querySelector('my-button')?.shadowRoot?.querySelector('button')
33-
}

examples/lit/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"experimentalDecorators": true,
66
"module": "node16",
77
"moduleResolution": "Node16",
8+
"types": ["@vitest/browser/providers/playwright"],
89
"verbatimModuleSyntax": true
910
}
1011
}

examples/lit/vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default defineConfig({
99
// https://lit.dev/docs/tools/testing/#testing-in-the-browser
1010
browser: {
1111
enabled: true,
12-
name: 'chrome',
13-
provider: 'webdriverio',
12+
name: 'chromium',
13+
provider: 'playwright',
1414
},
1515
},
1616
})

examples/workspace/packages/client/test/basic.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ test('Link changes the state when hovered', async () => {
1515

1616
await userEvent.hover(link)
1717

18-
expect(link).toHaveAccessibleName('Link is hovered')
18+
await expect.poll(() => link).toHaveAccessibleName('Link is hovered')
1919

2020
await userEvent.unhover(link)
2121

22-
expect(link).toHaveAccessibleName('Link is normal')
22+
await expect.poll(() => link).toHaveAccessibleName('Link is normal')
2323
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
},
6969
"pnpm": {
7070
"overrides": {
71+
"@vitest/browser": "workspace:*",
7172
"acorn": "8.11.3",
7273
"mlly": "^1.7.1",
7374
"rollup": "$rollup",

0 commit comments

Comments
 (0)