Description
@testing-library/dom
version: 8.6.0 (via@testing-library/[email protected]
- Testing Framework and version: jest 26.6.3
- DOM Environment: jsdom 16.4.0
Relevant code or config:
This is likely a small oversight from this PR:
https://github.com/testing-library/dom-testing-library/pull/1016/files#diff-bd112f388b709e19de79e65dceba95e350e0cd11b3aa198813c67a0121055792R70-L65
The resulting types:
export function buildQueries<Arguments extends any[]>(
queryAllBy: GetAllBy<Arguments>,
getMultipleError: GetErrorFunction,
getMissingError: GetErrorFunction,
): BuiltQueryMethods<Arguments>
What you did:
Here's a contrived example of a custom query that takes two arguments. Let's try to use these arguments to show a better error message:
buildQueries(
(container: HTMLElement, key: string | RegExp, value: string | RegExp) =>
doMagic(container, key, value),
(_container, ...args) => {
const [key, value] = args;
return `Found multiple with key ${key.toString()} and value ${value.toString()}`;
},
() => `Found none`,
);
What happened:
The types for the arguments to GetErrorFunction
are stuck at the default. At runtime, you can log ...args
and see that the expected key
and value
are passed.
Reproduction:
I can try to put together a TS repo if you need it, but here's all the code you need to see it:
import { buildQueries } from '@testing-library/react';
const doMagic = (_args: {
container: HTMLElement;
key: string | RegExp;
value: string | RegExp;
}) => [];
buildQueries(
(container: HTMLElement, key: string | RegExp, value: string | RegExp) =>
doMagic({ container, key, value }),
(_container, ...args) => {
const [key, value] = args;
return `Found multiple with key ${key.toString()} and value ${value.toString()}`;
},
() => `Found none`,
);
Problem description:
The types should match the intent and the runtime result and the GetErrorFunction
s for multiple/none in custom queries should accept the same Arguments
Suggested solution:
Forwarding Arguments
to GetErrorFunction
should do the trick