Skip to content

Commit

Permalink
feat: improve returned type for element getter (#2406)
Browse files Browse the repository at this point in the history
  • Loading branch information
nandi95 authored Apr 9, 2024
1 parent 4e3bda3 commit 5c22b4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/vueWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class VueWrapper<
}
}

get element(): Element {
get element(): T['$el'] {
// if the component has multiple root elements, we use the parent's element
return this.hasMultipleRoots ? this.parentElement : this.vm.$el
}
Expand Down
10 changes: 10 additions & 0 deletions test-dts/wrapper.d-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ const domWrapper = wrapper.find('#other')
let inputMaybe = wrapper.find('input')
expectType<HTMLInputElement | undefined>(inputMaybe.element)

let buttonComp = mount(
defineComponent({ template: '<button>Click me</button>' })
)
expectType<HTMLButtonElement>(buttonComp.element)

let multiRootComp = mount(defineComponent({ template: '<span /><span />' }))
// this will be a wrapper div element like so: <div data-v-app="">
expectType<HTMLDivElement>(multiRootComp.element)
expectType<HTMLSpanElement>(multiRootComp.element.firstElementChild)

// SVG element selector
let lineMaybe = wrapper.find('line')
expectType<SVGLineElement | undefined>(lineMaybe.element)
Expand Down

0 comments on commit 5c22b4e

Please sign in to comment.