Files
headlessui/packages/@headlessui-vue/src/test-utils/vue-testing-library.ts
T
Robin Malfait ce23edeee4 Next release (#431)
* Fixed typos (#350)

* chore: Fix typo in render.ts (#347)

* Better vue link (#353)

* Better vue link

* add better React link

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>

* Enable NoScroll feature for the initial useFocusTrap hook (#356)

* enable NoScroll feature for the initial useFocusTrap hook

Once you are using Tab and Shift+Tab it does the scrolling.

Fixes: #345

* update changelog

* Revert "Enable NoScroll feature for the initial useFocusTrap hook (#356)"

This reverts commit 19590b07624d7e3d751cbf11de869dfb0ea432ba.

Solution is not 100% correct, so will revert for now!

* Improve search (#385)

* make search case insensitive for the listbox

* make search case insensitive for the menu

* update changelog

* add `disabled` prop to RadioGroup and RadioGroup Option (#401)

* add `disabled` prop to RadioGroup and RadioGroup Option

Also did some general cleanup which in turn fixed an issue where the
RadioGroup is unreachable when a value is used that doesn't exist in the
list of options.

Fixes: #378

* update changelog

* Fix type of `RadioGroupOption` (#400)

Match RadioGroupOption value types to match modelValue allowed types for RadioGroup

* update changelog

* fix typo's

* chore(CI): update main workflow (#395)

* chore(CI): update main workflow

* Update main.yml

* fix dialog event propagation (#422)

* re-export the `screen` utility for quick debugging purposes

* stop event propagation when clicking inside a Dialog

Fixes: #414

* improve dialog escape (#430)

* Make sure that `Escape` only closes the top most Dialog

* update changelog

* add defaultOpen prop to Disclosure component (#447)

* add defaultOpen prop to Disclosure component

* update changelog

Co-authored-by: Shuvro Roy <shuvro.roy@northsouth.edu>
Co-authored-by: Alex Nault <nault.alex@gmail.com>
Co-authored-by: Eugene Kopich <github@web2033.com>
Co-authored-by: Nathan Shoemark <n.shoemark@gmail.com>
Co-authored-by: Michaël De Boey <info@michaeldeboey.be>
2021-04-26 15:44:10 +02:00

62 lines
1.5 KiB
TypeScript

import { mount } from '@vue/test-utils'
import { logDOM, fireEvent, screen } from '@testing-library/dom'
let mountedWrappers = new Set()
function resolveContainer(): HTMLElement {
let div = document.createElement('div')
let baseElement = document.body
let container = baseElement.appendChild(div)
let attachTo = document.createElement('div')
container.appendChild(attachTo)
return attachTo
}
export function render(TestComponent: any, options?: Parameters<typeof mount>[1] | undefined) {
let wrapper = mount(TestComponent, {
...options,
attachTo: options?.attachTo ?? resolveContainer(),
})
mountedWrappers.add(wrapper)
return {
get container() {
return wrapper.element.parentElement!
},
debug(element = wrapper.element.parentElement!) {
logDOM(element)
},
asFragment() {
let template = document.createElement('template')
template.innerHTML = wrapper.element.parentElement!.innerHTML
return template.content
},
}
}
function cleanup() {
mountedWrappers.forEach(cleanupAtWrapper)
document.body.innerHTML = ''
}
function cleanupAtWrapper(wrapper: any) {
if (wrapper.element.parentNode && wrapper.element.parentNode.parentNode === document.body) {
document.body.removeChild(wrapper.element.parentNode)
}
try {
wrapper.unmount()
} catch {
} finally {
mountedWrappers.delete(wrapper)
}
}
if (typeof afterEach === 'function') {
afterEach(() => cleanup())
}
export { fireEvent, screen }