forked from vitest-community/vitest-browser-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender-selector.test.tsx
More file actions
26 lines (18 loc) · 1.03 KB
/
render-selector.test.tsx
File metadata and controls
26 lines (18 loc) · 1.03 KB
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
import { expect, test } from 'vitest'
import { render } from 'vitest-browser-react'
import { page, server } from 'vitest/browser'
test('should apply and use a unique testid as the root selector when it does not exists', async () => {
const screen = await render(<div>Render</div>)
const selector = page.elementLocator(screen.baseElement).selector
expect(selector).toMatch(/^internal:testid=\[[^\]]*\]$/)
})
test('should apply and use a unique testid as the locator selector when using default container', async () => {
const screen = await render(<div>Render</div>)
expect(screen.locator.selector).toMatch(/^internal:testid=\[[^\]]*\]$/)
})
test('should not override testid attribute if already set', async () => {
document.body.setAttribute(server.config.browser.locators.testIdAttribute, 'custom-id')
const screen = await render(<div>Render</div>)
const selector = page.elementLocator(screen.baseElement).selector
expect(selector).toBe(`internal:testid=[${server.config.browser.locators.testIdAttribute}="custom-id"s]`)
})