-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
react.spec.ts
45 lines (40 loc) · 1.45 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { expect, test } from 'vitest'
import { editFile, isServe, page, untilUpdated } 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('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 meta = await page.evaluate(() => {
const button = document.querySelector('button')
const key = Object.keys(button).find(
(key) => key.indexOf('__reactFiber') === 0
)
return button[key]._debugSource
})
// If the evaluate call doesn't crash, and the returned metadata has
// the expected fields, we're good.
expect(Object.keys(meta).sort()).toEqual([
'columnNumber',
'fileName',
'lineNumber'
])
}
)
test('defined/reserved words are preserved in string literals', async () => {
expect(await page.textContent('.define-variable')).toBe(
'import' + '.meta.env' // FIXME: Workaround Vite replacement of import\0.meta.env
)
})