-
-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathreact.spec.ts
29 lines (25 loc) · 1000 Bytes
/
react.spec.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
import { expect, test } from 'vitest'
import { editFile, isServe, page, untilUpdated, viteTestUrl } from '~utils'
test('should render', async () => {
expect(await page.textContent('h1')).toMatch('Hello Vite + React')
})
test('should update', async () => {
expect(await page.textContent('button')).toMatch('count is: 0')
await page.click('button')
expect(await page.textContent('button')).toMatch('count is: 1')
})
test.runIf(isServe)('should hmr', async () => {
editFile('App.jsx', (code) => code.replace('Vite + React', 'Updated'))
await untilUpdated(() => page.textContent('h1'), 'Hello Updated')
// preserve state
expect(await page.textContent('button')).toMatch('count is: 1')
})
test.runIf(isServe)(
'should have annotated jsx with file location metadata',
async () => {
const res = await page.request.get(viteTestUrl + '/App.jsx')
const code = await res.text()
expect(code).toMatch(/lineNumber:\s*\d+/)
expect(code).toMatch(/columnNumber:\s*\d+/)
},
)