mirror of
https://github.com/hanzoai/vitest.git
synced 2026-09-24 17:04:25 +00:00
23 lines
700 B
TypeScript
23 lines
700 B
TypeScript
import { expect, test } from 'vitest'
|
|
import { render } from './utils'
|
|
|
|
test('.toHaveFocus', () => {
|
|
const {container} = render(`
|
|
<div>
|
|
<label for="focused">test</label>
|
|
<input id="focused" type="text" />
|
|
<button type="submit" id="not-focused">Not Focused</button>
|
|
</div>`)
|
|
|
|
const focused = container.querySelector('#focused') as HTMLInputElement
|
|
const notFocused = container.querySelector('#not-focused')
|
|
|
|
document.body.appendChild(container)
|
|
focused.focus()
|
|
|
|
expect(focused).toHaveFocus()
|
|
expect(notFocused).not.toHaveFocus()
|
|
|
|
expect(() => expect(focused).not.toHaveFocus()).toThrow()
|
|
expect(() => expect(notFocused).toHaveFocus()).toThrow()
|
|
}) |