Skip to content
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

Types for queryByTestId not correct #135

Closed
ssylvia opened this issue Oct 23, 2018 · 5 comments · Fixed by #139
Closed

Types for queryByTestId not correct #135

ssylvia opened this issue Oct 23, 2018 · 5 comments · Fixed by #139
Labels

Comments

@ssylvia
Copy link

ssylvia commented Oct 23, 2018

  • dom-testing-library version: 3.11.2

Relevant code or config:

screen shot 2018-10-23 at 8 27 28 am

What you did:

Used queryByTestId in typescript

What happened:

VSCode gives error that more arguments are expected

Problem description:

Looks like queryByTestId uses the queryByAttribute type: https://github.com/kentcdodds/dom-testing-library/blob/master/typings/queries.d.ts#L52, even thought the attribute argument is automatically bound: https://github.com/kentcdodds/dom-testing-library/blob/master/src/queries.js#L153.

Suggested solution:

Add a new type or pick the keys off the queryByAttribute type.

@ssylvia
Copy link
Author

ssylvia commented Oct 23, 2018

Looks like this might be a regression from 3.11.1 PR #130.

@alexwendte
Copy link
Collaborator

alexwendte commented Oct 23, 2018

I do not understand typescript very well, but it looks like the arguments for the queryBy and getBy functions are being inferred.

https://github.com/kentcdodds/dom-testing-library/blob/f29f551b1d9b031b0d8cf2d2dc436eae229ecc1d/typings/get-queries-for-element.d.ts#L4-L10

The queryByAltText type is broken as well.

@alexwendte
Copy link
Collaborator

I can confirm that removing line 8 makes the types work again. I don't know if that is the correct solution though or not.

https://github.com/kentcdodds/dom-testing-library/blob/4b62bf537687e2cb7bf5ce26c56e51a011e51231/typings/query-helpers.d.ts#L7-L12

On a different note, I am curious why the same typing was not applied to the getByAttribute function.

@jgoz
Copy link
Contributor

jgoz commented Oct 25, 2018

This is happening because the argument order for attribute and container is wrong on QueryByAttribute. I'll open a PR.

jgoz added a commit to jgoz/dom-testing-library that referenced this issue Oct 25, 2018
kentcdodds pushed a commit that referenced this issue Oct 25, 2018
* fix(typings): handle double-bound functions

fixes #135

* Add contributor
@kentcdodds
Copy link
Member

🎉 This issue has been resolved in version 3.12.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants