Skip to content

Commit

Permalink
fix: revert default element typings to HTMLElement
Browse files Browse the repository at this point in the history
The type definitions were updated to allow generic element typing in
#1871

However, this "loosened" the default type from `HTMLElement` to
`Element. This was actually a breaking change.

For example, consumers may have had this test code:

```ts
wrapper.element.click()
```

But `click()` only exists on `HTMLElement`, not on `Element`, so test
compilation fails.

This change moves the default type back to `HTMLElement`. If we want to
loosen this requirement in the future, it should be considered a
breaking change.
  • Loading branch information
alecgibson committed Jul 23, 2021
1 parent d56d945 commit d34b00b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/test-utils/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ interface BaseWrapper {
selector: Selector | void
}

export interface Wrapper<V extends Vue | null, el extends Element = Element> extends BaseWrapper {
export interface Wrapper<V extends Vue | null, el extends HTMLElement = HTMLElement> extends BaseWrapper {
readonly vm: V
readonly element: el
readonly options: WrapperOptions

get<R extends Vue> (selector: VueClass<R>): Wrapper<R>
get<R extends Vue> (selector: ComponentOptions<R>): Wrapper<R>
get<Props = DefaultProps, PropDefs = PropsDefinition<Props>>(selector: FunctionalComponentOptions<Props, PropDefs>): Wrapper<Vue>
get<el extends Element>(selector: string): Wrapper<Vue, el>
get<el extends HTMLElement>(selector: string): Wrapper<Vue, el>
get (selector: RefSelector): Wrapper<Vue>
get (selector: NameSelector): Wrapper<Vue>

Expand All @@ -96,7 +96,7 @@ export interface Wrapper<V extends Vue | null, el extends Element = Element> ext
find<R extends Vue> (selector: VueClass<R>): Wrapper<R>
find<R extends Vue> (selector: ComponentOptions<R>): Wrapper<R>
find<Props = DefaultProps, PropDefs = PropsDefinition<Props>>(selector: FunctionalComponentOptions<Props, PropDefs>): Wrapper<Vue>
find<el extends Element>(selector: string): Wrapper<Vue, el>
find<el extends HTMLElement>(selector: string): Wrapper<Vue, el>
find (selector: RefSelector): Wrapper<Vue>
find (selector: NameSelector): Wrapper<Vue>

Expand Down
1 change: 1 addition & 0 deletions packages/test-utils/types/test/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ found = wrapper.find({ name: 'my-button' })
selector = found.selector

wrapper.find<HTMLInputElement>('input').element.value
wrapper.find('div').element.click()

let array = wrapper.findAll('.bar')
selector = array.selector
Expand Down

0 comments on commit d34b00b

Please sign in to comment.