From df4e33dc2e399a78d67f5ed874ca4869e1db398a Mon Sep 17 00:00:00 2001 From: Nandor Kraszlan Date: Mon, 8 Apr 2024 21:43:26 +0100 Subject: [PATCH 1/2] Added dynamic return for element getter --- src/vueWrapper.ts | 2 +- test-dts/wrapper.d-test.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vueWrapper.ts b/src/vueWrapper.ts index b69bc85da..67c1f4864 100644 --- a/src/vueWrapper.ts +++ b/src/vueWrapper.ts @@ -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 } diff --git a/test-dts/wrapper.d-test.ts b/test-dts/wrapper.d-test.ts index 1582f3d95..4fc4179f2 100644 --- a/test-dts/wrapper.d-test.ts +++ b/test-dts/wrapper.d-test.ts @@ -14,6 +14,9 @@ const domWrapper = wrapper.find('#other') let inputMaybe = wrapper.find('input') expectType(inputMaybe.element) +let buttonComp = mount(defineComponent({ template: '' })) +expectType(buttonComp.element) + // SVG element selector let lineMaybe = wrapper.find('line') expectType(lineMaybe.element) From 3df75580470a85358fc919f7d114fb3a313caadb Mon Sep 17 00:00:00 2001 From: Nandor Kraszlan Date: Tue, 9 Apr 2024 14:02:02 +0100 Subject: [PATCH 2/2] Added multi root type test --- test-dts/wrapper.d-test.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test-dts/wrapper.d-test.ts b/test-dts/wrapper.d-test.ts index 4fc4179f2..4c25fabf0 100644 --- a/test-dts/wrapper.d-test.ts +++ b/test-dts/wrapper.d-test.ts @@ -14,9 +14,16 @@ const domWrapper = wrapper.find('#other') let inputMaybe = wrapper.find('input') expectType(inputMaybe.element) -let buttonComp = mount(defineComponent({ template: '' })) +let buttonComp = mount( + defineComponent({ template: '' }) +) expectType(buttonComp.element) +let multiRootComp = mount(defineComponent({ template: '' })) +// this will be a wrapper div element like so:
+expectType(multiRootComp.element) +expectType(multiRootComp.element.firstElementChild) + // SVG element selector let lineMaybe = wrapper.find('line') expectType(lineMaybe.element)