Description
@testing-library/dom
version: 7.20.0, broken by feat: add allowed roles to role query types #670
Relevant code or config:
Based on the tests in @testing-library/vue
on Definitely Typed:
import { queries, BoundFunction } from '@testing-library/dom';
declare var y: BoundFunction<typeof queries.getByRole>
y(/some text/, {exact: true, trim: false, collapseWhitespace: true, normalizer: x => x}); // $ExpectType HTMLElement
As of 7.20.0, this gives an error on the regex /some text/
. It also gives an error on the string "some text".
This is because BoundFunction
is a conditional type that does not understand multiple overloads, but #670 introduced multiple overloads for getByRole
in order to improve completions for ARIARole. Getting rid of the overloads fixes the problem.
has a bad interaction between the overloads of getByRole
in queries.d.ts
and the conditional type BoundFunction
in get-queries-for-element. But the types were so complex that I didn't have time to finish debugging it.
What you did:
Running tests for Definitely Typed, including @testing-library/vue
: https://dev.azure.com/definitelytyped/DefinitelyTyped/_build/results?buildId=53614&view=logs&j=b2dd9be2-fb32-52f8-c4c9-7dc0bc384587&t=f2dea62c-b696-5a51-78ad-206032e0a320&l=22288
What happened:
Error in testing-library__vue
Error: /home/vsts/work/1/s/DefinitelyTyped/types/testing-library__vue/testing-library__vue-tests.ts:69:21
ERROR: 69:21 expect [email protected] compile error:
Argument of type 'RegExp' is not assignable to parameter of type 'ARIARole'.
Type 'RegExp' is not assignable to type '"alertdialog"'.
Problem description:
Previously, arbitrary strings, regexes and matcher functions were allowed as the first argument to BoundFunction<getByRole>
. Now only literal string types that are part of ARIARole are allowed.
Suggested solution:
Just getting rid of the second overload didn't fix the problem for me; I had to create a new type alias like queries.d.ts used to have.
On the other hand, I don't know why the ComponentHarness interface in @testing-library/vue inherits from BoundFunctions in:
export interface ComponentHarness extends BoundFunctions<typeof queries> {
container: HTMLElement;
baseElement: HTMLBodyElement;
debug(el?: HTMLElement): void;
unmount(): void;
isUnmounted(): boolean;
html(): string;
emitted(): { [name: string]: any[][] };
updateProps(props: object): Promise<void>;
}
So it's possible that's not a reasonable thing to do. Maybe @cimbul can explain that — I couldn't find any documentation on BoundFunctions anywhere.