Skip to content
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

chore: update lit example to use the new locators API #6628

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/lit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
},
"devDependencies": {
"@vitest/browser": "latest",
"@vitest/ui": "latest",
"jsdom": "latest",
"playwright": "^1.47.2",
"vite": "latest",
"vitest": "latest",
"webdriverio": "^8.32.2"
"vitest": "latest"
},
"stackblitz": {
"startCommand": "npm run test:ui"
Expand Down
27 changes: 7 additions & 20 deletions examples/lit/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { beforeEach, describe, expect, it } from 'vitest'
import { page } from '@vitest/browser/context'

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

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

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

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

it('should dispatch count event on button click', () => {
const spyClick = vi.fn()

document.querySelector('my-button')!.addEventListener('count', spyClick)

getInsideButton()?.click()

expect(spyClick).toHaveBeenCalled()
it('should show name props', async () => {
await expect.element(page.getByRole('heading')).toHaveTextContent('World')
})
})

function getInsideButton(): HTMLElement | null | undefined {
return document.body.querySelector('my-button')?.shadowRoot?.querySelector('button')
}
1 change: 1 addition & 0 deletions examples/lit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"experimentalDecorators": true,
"module": "node16",
"moduleResolution": "Node16",
"types": ["@vitest/browser/providers/playwright"],
"verbatimModuleSyntax": true
}
}
4 changes: 2 additions & 2 deletions examples/lit/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default defineConfig({
// https://lit.dev/docs/tools/testing/#testing-in-the-browser
browser: {
enabled: true,
name: 'chrome',
provider: 'webdriverio',
name: 'chromium',
provider: 'playwright',
},
},
})
4 changes: 2 additions & 2 deletions examples/workspace/packages/client/test/basic.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ test('Link changes the state when hovered', async () => {

await userEvent.hover(link)

expect(link).toHaveAccessibleName('Link is hovered')
await expect.poll(() => link).toHaveAccessibleName('Link is hovered')

await userEvent.unhover(link)

expect(link).toHaveAccessibleName('Link is normal')
await expect.poll(() => link).toHaveAccessibleName('Link is normal')
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
},
"pnpm": {
"overrides": {
"@vitest/browser": "workspace:*",
"acorn": "8.11.3",
"mlly": "^1.7.1",
"rollup": "$rollup",
Expand Down
Loading