Given the following:
export const myQueryByTestId = queryHelpers.queryByAttribute.bind(
null,
'data-test-id',
);
test('...', async () => {
const view = await render(MyComponent, {
queries: {
...queries,
myQueryByTestId,
},
});
expect(view.myQueryByTestId('foo')).toBe(view.queryByTestId('foo'));
});
TypeScript throws an error when trying to use view.myQueryByTestId('foo'):
Property 'myQueryByTestId' does not exist on type 'RenderResult<MyComponent, MyComponent>'.
This is because RenderResult extends RenderQueryResults instead of intersects with it and passes the type of queries to RenderQueryResults.
Given the following:
TypeScript throws an error when trying to use
view.myQueryByTestId('foo'):This is because
RenderResultextendsRenderQueryResultsinstead of intersects with it and passes the type ofqueriestoRenderQueryResults.