1- /* eslint-disable @typescript-eslint/no-unused-expressions */
1+ import { expectType } from 'tsd'
22import { defineComponent } from 'vue'
3- import { render , fireEvent , screen , waitFor } from '@testing-library/vue '
3+ import { render , fireEvent , screen , waitFor } from '. '
44
55declare const elem : Element
66
@@ -16,29 +16,28 @@ export async function testRender() {
1616 const utils = render ( { template : '<div />' } )
1717
1818 // single queries
19- utils . getByText ( 'foo' )
20- utils . queryByText ( 'foo' )
21- await utils . findByText ( 'foo' )
19+ expectType < HTMLElement > ( utils . getByText ( 'foo' ) )
20+ expectType < HTMLElement | null > ( utils . queryByText ( 'foo' ) )
21+ expectType < HTMLElement > ( await utils . findByText ( 'foo' ) )
2222
2323 // multiple queries
24- utils . getAllByText ( 'bar' )
25- utils . queryAllByText ( 'bar' )
26- await utils . findAllByText ( 'bar' )
24+ expectType < HTMLElement [ ] > ( utils . getAllByText ( 'bar' ) )
25+ expectType < HTMLElement [ ] > ( utils . queryAllByText ( 'bar' ) )
26+ expectType < HTMLElement [ ] > ( await utils . findAllByText ( 'bar' ) )
2727
2828 // helpers
2929 const { container, baseElement, unmount, debug, rerender} = utils
3030
31- // eslint-disable-next-line @typescript-eslint/no-floating-promises
32- rerender ( { a : 1 } ) // $ExpectType Promise<void>
31+ expectType < void > ( await rerender ( { a : 1 } ) )
3332
34- debug ( ) // $ExpectType void
35- debug ( container ) // $ExpectType void
36- debug ( [ elem , elem ] , 100 , { highlight : false } ) // $ExpectType void
33+ expectType < void > ( debug ( ) )
34+ expectType < void > ( debug ( container ) )
35+ expectType < void > ( debug ( [ elem , elem ] , 100 , { highlight : false } ) )
3736
38- unmount ( ) // $ExpectType void
37+ expectType < void > ( unmount ( ) )
3938
40- container // $ExpectType Element
41- baseElement // $ExpectType Element
39+ expectType < Element > ( container )
40+ expectType < Element > ( baseElement )
4241}
4342
4443export function testRenderOptions ( ) {
@@ -50,20 +49,20 @@ export function testRenderOptions() {
5049
5150export async function testFireEvent ( ) {
5251 const { container} = render ( { template : 'button' } )
53- await fireEvent . click ( container ) // $ExpectType Promise<void>
54- await fireEvent . touch ( elem ) // $ExpectType Promise<void>
52+ expectType < void > ( await fireEvent . click ( container ) )
53+ expectType < void > ( await fireEvent . touch ( elem ) )
5554}
5655
5756export async function testScreen ( ) {
5857 render ( { template : 'button' } )
5958
60- await screen . findByRole ( 'button' ) // $ExpectType Promise<HTMLElement>
59+ expectType < HTMLElement > ( await screen . findByRole ( 'button' ) )
6160}
6261
6362export async function testWaitFor ( ) {
6463 const { container} = render ( { template : 'button' } )
65- await fireEvent . update ( container ) // $ExpectType Promise<void>
66- await waitFor ( ( ) => { } )
64+ expectType < void > ( await fireEvent . update ( container ) )
65+ expectType < void > ( await waitFor ( ( ) => { } ) )
6766}
6867
6968export function testOptions ( ) {
@@ -86,7 +85,7 @@ export function testOptions() {
8685
8786export function testEmitted ( ) {
8887 const { emitted} = render ( SomeComponent )
89- emitted ( ) . foo // $ExpectType unknown[]
88+ expectType < unknown [ ] > ( emitted ( ) . foo )
9089}
9190
9291/*
9695 testing-library/no-debug: "off",
9796 testing-library/prefer-screen-queries: "off",
9897 @typescript -eslint/unbound-method: "off",
98+ @typescript -eslint/no-invalid-void-type: "off"
9999*/
0 commit comments