Skip to content

Custom queries passed to render do not exist on the RenderResult according to TypeScript #590

Description

@bryanforbes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions