Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): Enable typecheck #189

Merged
merged 3 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test": "kcd-scripts test",
"test:update": "npm test -- --updateSnapshot --coverage",
"validate": "kcd-scripts validate",
"typecheck": "tsd",
"setup": "npm install && npm run validate -s"
},
"engines": {
Expand Down Expand Up @@ -60,7 +61,6 @@
"@vue/compiler-sfc": "^3.1.1",
"apollo-boost": "^0.4.9",
"axios": "^0.20.0",
"dtslint": "^4.1.0",
"element-plus": "^1.0.2-beta.64",
"eslint-plugin-vue": "^7.14.0",
"graphql": "^15.5.0",
Expand All @@ -70,6 +70,7 @@
"kcd-scripts": "^10.0.0",
"lodash.merge": "^4.6.2",
"msw": "^0.21.3",
"tsd": "^0.17.0",
"typescript": "^4.3.5",
"vee-validate": "^4.3.5",
"vue": "^3.0.4",
Expand Down
44 changes: 22 additions & 22 deletions types/test.ts → types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-expressions */
import {expectType} from 'tsd'
import {defineComponent} from 'vue'
import {render, fireEvent, screen, waitFor} from '@testing-library/vue'
import {render, fireEvent, screen, waitFor} from '.'

declare const elem: Element

Expand All @@ -16,29 +16,28 @@ export async function testRender() {
const utils = render({template: '<div />'})

// single queries
utils.getByText('foo')
utils.queryByText('foo')
await utils.findByText('foo')
expectType<HTMLElement>(utils.getByText('foo'))
expectType<HTMLElement | null>(utils.queryByText('foo'))
expectType<HTMLElement>(await utils.findByText('foo'))

// multiple queries
utils.getAllByText('bar')
utils.queryAllByText('bar')
await utils.findAllByText('bar')
expectType<HTMLElement[]>(utils.getAllByText('bar'))
expectType<HTMLElement[]>(utils.queryAllByText('bar'))
expectType<HTMLElement[]>(await utils.findAllByText('bar'))

// helpers
const {container, baseElement, unmount, debug, rerender} = utils

// eslint-disable-next-line @typescript-eslint/no-floating-promises
rerender({a: 1}) // $ExpectType Promise<void>
expectType<void>(await rerender({a: 1}))

debug() // $ExpectType void
debug(container) // $ExpectType void
debug([elem, elem], 100, {highlight: false}) // $ExpectType void
expectType<void>(debug())
expectType<void>(debug(container))
expectType<void>(debug([elem, elem], 100, {highlight: false}))

unmount() // $ExpectType void
expectType<void>(unmount())

container // $ExpectType Element
baseElement // $ExpectType Element
expectType<Element>(container)
expectType<Element>(baseElement)
}

export function testRenderOptions() {
Expand All @@ -50,20 +49,20 @@ export function testRenderOptions() {

export async function testFireEvent() {
const {container} = render({template: 'button'})
await fireEvent.click(container) // $ExpectType Promise<void>
await fireEvent.touch(elem) // $ExpectType Promise<void>
expectType<void>(await fireEvent.click(container))
expectType<void>(await fireEvent.touch(elem))
}

export async function testScreen() {
render({template: 'button'})

await screen.findByRole('button') // $ExpectType Promise<HTMLElement>
expectType<HTMLElement>(await screen.findByRole('button'))
}

export async function testWaitFor() {
const {container} = render({template: 'button'})
await fireEvent.update(container) // $ExpectType Promise<void>
await waitFor(() => {})
expectType<void>(await fireEvent.update(container))
expectType<void>(await waitFor(() => {}))
}

export function testOptions() {
Expand All @@ -86,7 +85,7 @@ export function testOptions() {

export function testEmitted() {
const {emitted} = render(SomeComponent)
emitted().foo // $ExpectType unknown[]
expectType<unknown[]>(emitted().foo)
}

/*
Expand All @@ -96,4 +95,5 @@ eslint
testing-library/no-debug: "off",
testing-library/prefer-screen-queries: "off",
@typescript-eslint/unbound-method: "off",
@typescript-eslint/no-invalid-void-type: "off"
*/