-
Notifications
You must be signed in to change notification settings - Fork 471
fix(types): allow bound function to accept string and regex matcher #683
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
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 5d628fa:
|
Codecov Report
@@ Coverage Diff @@
## master #683 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 24 24
Lines 614 614
Branches 156 156
=========================================
Hits 614 614 Continue to review full report at Codecov.
|
types/matches.d.ts
Outdated
// resulting in no intellisense | ||
// We still want to support roles not included in the union type | ||
/* tslint:disable:ban-types */ | ||
export type ByRoleMatcher = ARIARole | String | RegExp | MatcherFunction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This use case is tracked in microsoft/TypeScript#29729.
I'd prefer we go with the approach that is documented in that issue: 'literal' | (string & {})
(microsoft/TypeScript#29729 (comment)). Then we at least follow community best practices. And we should probably link the issue in the comment in case it gets resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯 I was looking for a workaround but I couldn't find any.
Thanks for also giving this a look @eps1lon , this is simply great!
@timdeschryver looks 7.20.0 also broke @testing-library/testcafe as well with the following failure: FAIL ./selectors.test.ts
[test:unit:monorepo] ● Test suite failed to run
[test:unit:monorepo]
[test:unit:monorepo] ../../src/index.ts:71:14 - error TS2349: This expression is not callable.
[test:unit:monorepo] Each member of the union type '{ (container: HTMLElement, role: Matcher, options?: ByRoleOptions | undefined): HTMLElement[]; (container: HTMLElement, role: ARIARole, options?: ByRoleOptions | undefined): HTMLElement[]; } | ... 13 more ... | FindAllByBoundAttribute' has signatures, but none of those signatures are compatible with each other.
[test:unit:monorepo]
[test:unit:monorepo] 71 return window.TestingLibraryDom[query](
[test:unit:monorepo] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[test:unit:monorepo]
[test:unit:monorepo] Test Suites: 1 failed, 1 total Here's the link w/ all the details: https://github.com/testing-library/testcafe-testing-library/pull/204/checks?check_run_id=830176994 seems related, but maybe i'm wrong... |
@benmonro this fix should also resolve that issue. |
I have rebased this branch, should be good to go for another review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine to me, but I'm not super experienced with TypeScript and would prefer someone else give this the 👍
Anyone with rights can feel free to merge. |
🎉 This PR is included in version 7.21.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
What:
byRole
queries (for example withscreen
) in combination with a string or regexp matcher,screen.getByRole('foo')
orscreen.getByRole(/head/)
. The types only allow an ARIARole, e.g.screen.getByRole('button')
Why:
How:
getByRole
queriesByRoleMatcher
that uses theString
type instead of thestring
type we can have intellisense while not introducing a breaking change (we are still able to use a string that isn't included in theAriaRole
union).Checklist:
docs site
I think for now, using
String
is the best solution. We can provide intellisense while not introducing a breaking change. We could revisit the types when we release a new major version.