Skip to content

Conversation

cexbrayat
Copy link
Member

It currently returns an Element whereas VTU v1 returned an HTMLElement (allowing to access more properties).

https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/types/index.d.ts#L78

Copy link
Member

@afontcu afontcu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Quick question: Would it work if we use find to return a SVG element? I think its type is SVGElement, so I'm not so sure. Disclaimer: I'm by no means a typescript expert! 😇

@lmiller1990
Copy link
Member

lmiller1990 commented Apr 18, 2020

Right, that's why I think element is more correct - that's what querySelector returns. And find is generic so people can hint at what they are expecting. Eg find<SVGLineElement>('line') will work as expected with correct intellisense.

The types in beta were written by hand, now we have "native" types for things like querySelector isn't it ideal to use those?

@cexbrayat cexbrayat force-pushed the fix/html-element branch 2 times, most recently from 610219a to c949e4a Compare April 19, 2020 10:45
@cexbrayat
Copy link
Member Author

Fair point! I didn't think about SVGElement.

But It made me think, and we can do way better in fact. I pushed a new commit, PTAL @afontcu @lmiller1990 .

This commit allows to have a better type inference of find, get and findAll methods.
For example, wrapper.find('input').element is now inferred as a HTMLInputElement | undefined. It also works with SVG element: wrapper.get('line').element is inferred as a SVGLineElement. For ambiguous selectors, we fallback to the generic element type: wrapper.get('#other').element is inferred as Element.

@cexbrayat cexbrayat changed the title fix: DOMWrapper returns HTMLElement fix: improve typings of find/get/findAll Apr 19, 2020
This commit allows to have a better type inference of `find`, `get` and `findAll` methods.
For example, `wrapper.find('input').element` is now inferred as a `HTMLInputElement | undefined`. It also works with SVG element: `wrapper.get('line').element` is inferred as a `SVGLineElement`. For ambiguous selectors, we fallback to the generic element type: `wrapper.get('#other').element` is inferred as `Element`.
@cexbrayat cexbrayat requested a review from afontcu April 21, 2020 07:03
@lmiller1990
Copy link
Member

Had not seen the HTMLElementTagNameMap type... very cool. Thanks for fixing up the TS for us!

@lmiller1990 lmiller1990 self-requested a review April 21, 2020 08:25
@lmiller1990 lmiller1990 merged commit f26e0d4 into vuejs:master Apr 21, 2020
@cexbrayat
Copy link
Member Author

Yep it's pretty cool! Thank you for merging it 🙂

Do you plan to release another alpha? It would be great to test-drive all our fixes/improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants