Skip to content

Commit 68883d5

Browse files
committed
make typescript happy
1 parent ec8e3cb commit 68883d5

File tree

19 files changed

+231
-219
lines changed

19 files changed

+231
-219
lines changed

packages/@headlessui-vue/src/components/description/description.test.ts

+67-70
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { html } from '../../test-utils/html'
88
import { click } from '../../test-utils/interactions'
99
import { getByText } from '../../test-utils/accessibility-assertions'
1010

11-
function format(input: Element | string) {
11+
function format(input: Element | null | string) {
12+
if (input === null) throw new Error('input is null')
1213
let contents = (typeof input === 'string' ? input : (input as HTMLElement).outerHTML).trim()
1314
return prettier.format(contents, { parser: 'babel' })
1415
}
@@ -22,32 +23,19 @@ beforeAll(() => {
2223

2324
afterAll(() => jest.restoreAllMocks())
2425

25-
function renderTemplate(input: string | Partial<Parameters<typeof defineComponent>[0]>) {
26-
let defaultComponents = { Description }
27-
28-
if (typeof input === 'string') {
29-
return render(defineComponent({ template: input, components: defaultComponents }))
30-
}
31-
32-
return render(
33-
defineComponent(
34-
Object.assign({}, input, {
35-
components: { ...defaultComponents, ...input.components },
36-
}) as Parameters<typeof defineComponent>[0]
37-
)
38-
)
39-
}
40-
4126
it('should be possible to use useDescriptions without using a Description', async () => {
42-
let { container } = renderTemplate({
43-
render() {
44-
return h('div', [h('div', { 'aria-describedby': this.describedby }, ['No description'])])
45-
},
46-
setup() {
47-
let describedby = useDescriptions()
48-
return { describedby }
49-
},
50-
})
27+
let { container } = render(
28+
defineComponent({
29+
components: { Description },
30+
render() {
31+
return h('div', [h('div', { 'aria-describedby': this.describedby }, ['No description'])])
32+
},
33+
setup() {
34+
let describedby = useDescriptions()
35+
return { describedby }
36+
},
37+
})
38+
)
5139

5240
expect(format(container.firstElementChild)).toEqual(
5341
format(html`
@@ -59,20 +47,23 @@ it('should be possible to use useDescriptions without using a Description', asyn
5947
})
6048

6149
it('should be possible to use useDescriptions and a single Description, and have them linked', async () => {
62-
let { container } = renderTemplate({
63-
render() {
64-
return h('div', [
65-
h('div', { 'aria-describedby': this.describedby }, [
66-
h(Description, () => 'I am a description'),
67-
h('span', 'Contents'),
68-
]),
69-
])
70-
},
71-
setup() {
72-
let describedby = useDescriptions()
73-
return { describedby }
74-
},
75-
})
50+
let { container } = render(
51+
defineComponent({
52+
components: { Description },
53+
render() {
54+
return h('div', [
55+
h('div', { 'aria-describedby': this.describedby }, [
56+
h(Description, () => 'I am a description'),
57+
h('span', 'Contents'),
58+
]),
59+
])
60+
},
61+
setup() {
62+
let describedby = useDescriptions()
63+
return { describedby }
64+
},
65+
})
66+
)
7667

7768
await new Promise<void>(nextTick)
7869

@@ -89,21 +80,24 @@ it('should be possible to use useDescriptions and a single Description, and have
8980
})
9081

9182
it('should be possible to use useDescriptions and multiple Description components, and have them linked', async () => {
92-
let { container } = renderTemplate({
93-
render() {
94-
return h('div', [
95-
h('div', { 'aria-describedby': this.describedby }, [
96-
h(Description, () => 'I am a description'),
97-
h('span', 'Contents'),
98-
h(Description, () => 'I am also a description'),
99-
]),
100-
])
101-
},
102-
setup() {
103-
let describedby = useDescriptions()
104-
return { describedby }
105-
},
106-
})
83+
let { container } = render(
84+
defineComponent({
85+
components: { Description },
86+
render() {
87+
return h('div', [
88+
h('div', { 'aria-describedby': this.describedby }, [
89+
h(Description, () => 'I am a description'),
90+
h('span', 'Contents'),
91+
h(Description, () => 'I am also a description'),
92+
]),
93+
])
94+
},
95+
setup() {
96+
let describedby = useDescriptions()
97+
return { describedby }
98+
},
99+
})
100+
)
107101

108102
await new Promise<void>(nextTick)
109103

@@ -121,21 +115,24 @@ it('should be possible to use useDescriptions and multiple Description component
121115
})
122116

123117
it('should be possible to update a prop from the parent and it should reflect in the Description component', async () => {
124-
let { container } = renderTemplate({
125-
render() {
126-
return h('div', [
127-
h('div', { 'aria-describedby': this.describedby }, [
128-
h(Description, () => 'I am a description'),
129-
h('button', { onClick: () => this.count++ }, '+1'),
130-
]),
131-
])
132-
},
133-
setup() {
134-
let count = ref(0)
135-
let describedby = useDescriptions({ props: { 'data-count': count } })
136-
return { count, describedby }
137-
},
138-
})
118+
let { container } = render(
119+
defineComponent({
120+
components: { Description },
121+
render() {
122+
return h('div', [
123+
h('div', { 'aria-describedby': this.describedby }, [
124+
h(Description, () => 'I am a description'),
125+
h('button', { onClick: () => this.count++ }, '+1'),
126+
]),
127+
])
128+
},
129+
setup() {
130+
let count = ref(0)
131+
let describedby = useDescriptions({ props: { 'data-count': count } })
132+
return { count, describedby }
133+
},
134+
})
135+
)
139136

140137
await new Promise<void>(nextTick)
141138

packages/@headlessui-vue/src/components/dialog/dialog.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineComponent, ref, nextTick, h } from 'vue'
1+
import { defineComponent, ref, nextTick, h, ComponentOptionsWithoutProps } from 'vue'
22
import { render } from '../../test-utils/vue-testing-library'
33

44
import { Dialog, DialogOverlay, DialogTitle, DialogDescription } from './dialog'
@@ -42,7 +42,7 @@ beforeAll(() => {
4242

4343
afterAll(() => jest.restoreAllMocks())
4444

45-
function renderTemplate(input: string | Partial<Parameters<typeof defineComponent>[0]>) {
45+
function renderTemplate(input: string | ComponentOptionsWithoutProps) {
4646
let defaultComponents = { Dialog, DialogOverlay, DialogTitle, DialogDescription, TabSentinel }
4747

4848
if (typeof input === 'string') {

packages/@headlessui-vue/src/components/disclosure/disclosure.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineComponent, nextTick, ref, watch, h } from 'vue'
1+
import { defineComponent, nextTick, ref, watch, h, ComponentOptionsWithoutProps } from 'vue'
22
import { render } from '../../test-utils/vue-testing-library'
33
import { Disclosure, DisclosureButton, DisclosurePanel } from './disclosure'
44
import { suppressConsoleLogs } from '../../test-utils/suppress-console-logs'
@@ -19,7 +19,7 @@ jest.mock('../../hooks/use-id')
1919

2020
afterAll(() => jest.restoreAllMocks())
2121

22-
function renderTemplate(input: string | Partial<Parameters<typeof defineComponent>[0]>) {
22+
function renderTemplate(input: string | ComponentOptionsWithoutProps) {
2323
let defaultComponents = { Disclosure, DisclosureButton, DisclosurePanel }
2424

2525
if (typeof input === 'string') {

packages/@headlessui-vue/src/components/focus-trap/focus-trap.test.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineComponent, ref, nextTick, onMounted } from 'vue'
1+
import { defineComponent, ref, nextTick, onMounted, ComponentOptionsWithoutProps } from 'vue'
22

33
import { FocusTrap } from './focus-trap'
44
import { assertActiveElement, getByText } from '../../test-utils/accessibility-assertions'
@@ -16,7 +16,7 @@ beforeAll(() => {
1616

1717
afterAll(() => jest.restoreAllMocks())
1818

19-
function renderTemplate(input: string | Partial<Parameters<typeof defineComponent>[0]>) {
19+
function renderTemplate(input: string | ComponentOptionsWithoutProps) {
2020
let defaultComponents = { FocusTrap }
2121

2222
if (typeof input === 'string') {
@@ -41,7 +41,7 @@ it('should focus the first focusable element inside the FocusTrap', async () =>
4141
`
4242
)
4343

44-
await new Promise(nextTick)
44+
await new Promise<void>(nextTick)
4545

4646
assertActiveElement(getByText('Trigger'))
4747
})
@@ -64,7 +64,7 @@ it('should focus the autoFocus element inside the FocusTrap if that exists', asy
6464
},
6565
})
6666

67-
await new Promise(nextTick)
67+
await new Promise<void>(nextTick)
6868

6969
assertActiveElement(document.getElementById('b'))
7070
})
@@ -84,7 +84,7 @@ it('should focus the initialFocus element inside the FocusTrap if that exists',
8484
},
8585
})
8686

87-
await new Promise(nextTick)
87+
await new Promise<void>(nextTick)
8888

8989
assertActiveElement(document.getElementById('c'))
9090
})
@@ -104,7 +104,7 @@ it('should focus the initialFocus element inside the FocusTrap even if another e
104104
},
105105
})
106106

107-
await new Promise(nextTick)
107+
await new Promise<void>(nextTick)
108108

109109
assertActiveElement(document.getElementById('c'))
110110
})
@@ -121,7 +121,7 @@ it('should warn when there is no focusable element inside the FocusTrap', async
121121
`
122122
)
123123

124-
await new Promise(nextTick)
124+
await new Promise<void>(nextTick)
125125

126126
expect(spy.mock.calls[0][0]).toBe('There are no focusable elements inside the <FocusTrap />')
127127
})
@@ -143,7 +143,7 @@ it(
143143
`,
144144
})
145145

146-
await new Promise(nextTick)
146+
await new Promise<void>(nextTick)
147147

148148
let [a, b, c, d] = Array.from(document.querySelectorAll('input'))
149149

@@ -210,7 +210,7 @@ it('should restore the previously focused element, before entering the FocusTrap
210210
},
211211
})
212212

213-
await new Promise(nextTick)
213+
await new Promise<void>(nextTick)
214214

215215
// The input should have focus by default because of the autoFocus prop
216216
assertActiveElement(document.getElementById('item-1'))
@@ -243,7 +243,7 @@ it('should be possible to tab to the next focusable element within the focus tra
243243
`
244244
)
245245

246-
await new Promise(nextTick)
246+
await new Promise<void>(nextTick)
247247

248248
// Item A should be focused because the FocusTrap will focus the first item
249249
assertActiveElement(document.getElementById('item-a'))

0 commit comments

Comments
 (0)