Skip to content

queryByRole types aren't aligned to implementation #142

Closed
@chiefGui

Description

@chiefGui
  • dom-testing-library version: ^3.10.1
  • react version: ^16.6.0
  • node version: 9.2.0
  • npm (or yarn) version: yarn v1.10.1

Relevant code or config:

test("render tab title with icon", () => {
  expect(queryByRole(document.body, "figure")).toBeNull();

  render(
    <Tabs>
      <Tabs.Tab title="Home" icon={AlbumsIcon}>
        hello world
      </Tabs.Tab>
    </Tabs>
  );

  expect(queryByRole(document.body, "figure")).toBeTruthy();
});

What you did:

I've ran some tests.

What happened:

Tests are passing, but TypeScript is complaining.

Reproduction:

// index.test.tsx

import * as React from "react"
import { render, cleanup } from "react-testing-library"
import { queryByRole } from "dom-testing-library"
import { Something } from "."

afterEach(cleanup)

describe("something", () => {
  test("render role", () => {
    expect(queryByRole(document.body, "figure")).toBeNull()

    render(<Something />)

    expect(queryByRole(document.body, "figure")).toBeTruthy()
  })
})
// index.tsx

export const Something = () => <div role="figure" />

Problem description:

Basically, tests are passing, but TypeScript complains that queryByRole expects from 3-4 arguments and it's getting 2.

According to your typings, that seems expected though:

The first argument QueryAttribute expects is attribute: string;, but that doesn't make sense because the attribute I want is already expressed by queryByRole (which is role).

Same happens with queryByAltText. i.e.:

image

Suggested solution:

My suggested solution is to better design these interfaces to properly fit to the signatures of these methods that already have an explicit attribute. I can create a PR for that, just want to make sure if I'm not daydreaming or something.

Thanks!

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