fix types this way
jsjoeio opened this issue ยท 6 comments
Is this template still good for the latest versions of the different dependencies?
TypeScript in VS Code currently tells me Property 'toBeInTheDocument' does not exist on type 'Assertion<HTMLElement>'.
here
expect(screen.getByText("Learn React")).toBeInTheDocument();
and then other errors relating to describe in Avatar.test.tsx
Cannot find name 'describe'. Do you need to install type definitions
for a test runner? Try `npm i --save-dev @types/jest` or `npm i
--save-dev @types/mocha`.ts(2582)
I can fix the latter by importing describe, expect etc from vitest
, but not sure about the former.
The tests run just fine. I tried to force VS Code to use a local version of TypeScript 4.9.4, but that didn't make a difference.
Well, somewhere along the line my TS errors went away: https://github.com/jschuur/react-testing-test
I imagine this is related to the type narrowing that I'm doing:
const input = screen.getByRole('textbox');
if (!(input instanceof HTMLInputElement)) {
throw new Error('expected input to be an HTMLInputElement');
}
Is this template still good for the latest versions of the different dependencies?
I haven't tested it in a while so not sure unfortunately.
Well, somewhere along the line my TS errors went away: https://github.com/jschuur/react-testing-test
Ah nice!! So all is good then?
Ah nice!! So all is good then?
Yup. In the sense that eventually, in on my own project things randomly started working :)
I googled some of the error messages and found a few threads (including the one you were on) pointing at causes but it was a little beyond my abilities to understand. So I just hit it with a hammer until it worked.
So I just hit it with a hammer until it worked
Honestly...most days that is my approach if Google and ChatGPT fail me
Closing because who knows if I'll ever get around to fixing this