切换vitest-browser

This commit is contained in:
xief
2025-07-15 10:56:24 +08:00
parent cf9913469f
commit 87e2804d1f
10 changed files with 1749 additions and 223 deletions

View File

@@ -0,0 +1,11 @@
import { expect, test } from 'vitest'
import { getByText } from '@testing-library/dom'
import HelloWorld from './HelloWorld.js'
test('renders name', () => {
const parent = HelloWorld({ name: 'Vitest' })
document.body.appendChild(parent)
const element = getByText(parent, 'Hello Vitest!')
expect(element).toBeInTheDocument()
})

View File

@@ -0,0 +1,9 @@
export default function HelloWorld({ name }: { name: string }): HTMLDivElement {
const parent = document.createElement('div')
const h1 = document.createElement('h1')
h1.textContent = 'Hello ' + name + '!'
parent.appendChild(h1)
return parent
}