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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions