-
-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathreact.spec.ts
More file actions
33 lines (29 loc) · 1.14 KB
/
react.spec.ts
File metadata and controls
33 lines (29 loc) · 1.14 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
27
28
29
30
31
32
33
import { expect, test } from 'vitest'
import { editFile, isServe, page, viteTestUrl } from '~utils'
test('should render', async () => {
await expect.poll(() => 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 expect.poll(() => page.textContent('h1')).toMatch('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 () => {
let pathname = '/App.jsx'
if (process.env.VITE_TEST_FULL_BUNDLE_MODE) {
pathname = await (await page.$('script')).getAttribute('src')
}
const res = await page.request.get(new URL(pathname, viteTestUrl).href)
const code = await res.text()
expect(code).toMatch(/lineNumber:\s*\d+/)
expect(code).toMatch(/columnNumber:\s*\d+/)
},
)