Skip to content

Commit 5c22b4e

Browse files
authored
feat: improve returned type for element getter (#2406)
1 parent 4e3bda3 commit 5c22b4e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/vueWrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class VueWrapper<
213213
}
214214
}
215215

216-
get element(): Element {
216+
get element(): T['$el'] {
217217
// if the component has multiple root elements, we use the parent's element
218218
return this.hasMultipleRoots ? this.parentElement : this.vm.$el
219219
}

test-dts/wrapper.d-test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ const domWrapper = wrapper.find('#other')
1414
let inputMaybe = wrapper.find('input')
1515
expectType<HTMLInputElement | undefined>(inputMaybe.element)
1616

17+
let buttonComp = mount(
18+
defineComponent({ template: '<button>Click me</button>' })
19+
)
20+
expectType<HTMLButtonElement>(buttonComp.element)
21+
22+
let multiRootComp = mount(defineComponent({ template: '<span /><span />' }))
23+
// this will be a wrapper div element like so: <div data-v-app="">
24+
expectType<HTMLDivElement>(multiRootComp.element)
25+
expectType<HTMLSpanElement>(multiRootComp.element.firstElementChild)
26+
1727
// SVG element selector
1828
let lineMaybe = wrapper.find('line')
1929
expectType<SVGLineElement | undefined>(lineMaybe.element)

0 commit comments

Comments
 (0)