Argument of type 'Element' is not assignable to parameter of type 'HTMLElement'.
See original GitHub issue@testing-library/react
version: 11.2.2
Relevant code or config:
const { container } = render( // container is `Element` here
<MyComponent/>,
)
expect(getByText(container, someText)).toBeInTheDocument() // Error: Argument of type 'Element' is not assignable to parameter of type 'HTMLElement'.
expect(getByTestId(container, 'test-id')).toBeInTheDocument() // Error: Argument of type 'Element' is not assignable to parameter of type 'HTMLElement'.
Problem description:
After testing-library/react-testing-library#833 I get type errors because container
no more HTMLElement
.
container as HTMLElement
doesn’t seem like a good solution.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (13 by maintainers)
Top Results From Across the Web
angular - Argument of type 'HTMLElement' is not assignable to ...
You have to tell the compiler that the img variable is being set as an HTMLImageElement . The ctx.drawImage method expects a :...
Read more >Argument of type 'Element' is not assignable to ... - GitHub
// Error: Argument of type 'Element' is not assignable to parameter of type 'HTMLElement'. expect(getByTestId(container, 'test-id')).
Read more >How to fix Argument of type 'HTMLElement | null' is not ...
Tutorial on how to fix the error Argument of type 'HTMLElement | null' is not assignable to parameter of type 'Element | DocumentFragment'....
Read more >Argument type Element is not assignable to parameter type ...
Basically, I'm assigning a variable as follows: var basis_control = document.getElementById('flex-basis-field ...
Read more >Argument of type 'HTMLElement | null' is not assignable to ...
Coding example for the question Argument of type 'HTMLElement | null' is not assignable to parameter of type 'Element'. Type 'null' is not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Argh, I pasted the wrong link previously. They do have definitions: https://www.npmjs.com/package/@types/testing-library__jest-dom
getByText
andgetByTestId
are being re-exported upstream from DOM Testing Library, which hasn’t been updated to match React Testing Library yet (you can subscribe to the pull request for updates).There is also a separate issue with the runtime (not TypeScript) type checking in Jest DOM. I’ve opened https://github.com/testing-library/jest-dom/issues/313 to track that.