Skip to content

feat: add generic for wrapper.find() and wrapper.get() #1871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 12, 2021

Conversation

standbyoneself
Copy link
Contributor

@standbyoneself standbyoneself commented Jul 7, 2021

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • [x ] Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • [ x] No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

fix: #1870

This feature will allow to target already the need type of the Element e.g. SVGElement, HTMLElement or other

Example:

const input = wrapper.find<HTMLInputElement>('input')
console.log(input.element.value)

Copy link
Member

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

Thanks, one comment

@lmiller1990 lmiller1990 merged commit c2ee13b into vuejs:dev Jul 12, 2021
@alecgibson
Copy link

By defaulting to Element rather than HTMLElement this broke all our tests 😢

alecgibson added a commit to reedsy/vue-test-utils that referenced this pull request Jul 23, 2021
The type definitions were updated to allow generic element typing in
vuejs#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.
alecgibson added a commit to reedsy/vue-test-utils that referenced this pull request Jul 23, 2021
The type definitions were updated to allow generic element typing in
vuejs#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.
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.

Typescript error with wrapper.find('select').element.value
3 participants