import {expectType} from 'tsd' import {defineComponent} from 'vue' import {render, fireEvent, screen, waitFor} from '.' declare const elem: Element const SomeComponent = defineComponent({ name: 'SomeComponent', props: { foo: {type: Number, default: 0}, bar: {type: String, default: '0'}, }, }) export async function testRender() { const utils = render({template: '
'}) // single queries expectType(utils.getByText('foo')) expectType(utils.queryByText('foo')) expectType(await utils.findByText('foo')) // multiple queries expectType(utils.getAllByText('bar')) expectType(utils.queryAllByText('bar')) expectType(await utils.findAllByText('bar')) // helpers const {container, baseElement, unmount, debug, rerender} = utils expectType(await rerender({a: 1})) expectType(debug()) expectType(debug(container)) expectType(debug([elem, elem], 100, {highlight: false})) expectType(unmount()) expectType(container) expectType(baseElement) } export function testRenderOptions() { const container = document.createElement('div') const baseElement = document.createElement('div') const options = {container, baseElement} render({template: 'div'}, options) } export async function testFireEvent() { const {container} = render({template: 'button'}) expectType(await fireEvent.click(container)) expectType(await fireEvent.touch(elem)) } export async function testScreen() { render({template: 'button'}) expectType(await screen.findByRole('button')) } export async function testWaitFor() { const {container} = render({template: 'button'}) expectType(await fireEvent.update(container)) expectType(await waitFor(() => {})) } export function testOptions() { render(SomeComponent, { attrs: {a: 1}, props: {foo: 1}, data: () => ({b: 2}), slots: { default: '
', footer: '
', }, global: { config: {isCustomElement: _ => true}, plugins: [], }, baseElement: document.createElement('div'), container: document.createElement('div'), }) } export function testEmitted() { const {emitted} = render(SomeComponent) expectType(emitted().foo) expectType(emitted('foo')) } /* eslint testing-library/prefer-explicit-assert: "off", testing-library/no-wait-for-empty-callback: "off", testing-library/no-debugging-utils: "off", testing-library/prefer-screen-queries: "off", @typescript-eslint/unbound-method: "off", @typescript-eslint/no-invalid-void-type: "off" */