question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
eps1loncommented, Nov 26, 2020

but jest-dom doesn’t have any type definitions as far as I can see

Argh, I pasted the wrong link previously. They do have definitions: https://www.npmjs.com/package/@types/testing-library__jest-dom

0reactions
nickmccurdycommented, Dec 3, 2020

getByText and getByTestId 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found