-
Notifications
You must be signed in to change notification settings - Fork 467
Closed
Labels
Description
dom-testing-libraryversion:^3.10.1reactversion:^16.6.0nodeversion:9.2.0npm(oryarn) 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:
- https://github.com/kentcdodds/dom-testing-library/blob/master/typings/queries.d.ts#L64
- https://github.com/kentcdodds/dom-testing-library/blob/master/typings/query-helpers.d.ts#L7-L12
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.:
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!
