Search code examples
reactjstypescriptreact-typescript

Property 'getAllByRole' does not exist on type 'Screen'. TS2339


I'm working on a web application in which the front end is built using ReactJs. When I run the code, I'm getting this error as mentioned.

 TypeScript error in My_project/src/unitTestUtils.tsx(79,27):
Property 'getAllByRole' does not exist on type 'Screen'.  TS2339

  > 79 |   const rowGroups = scope.getAllByRole("rowgroup");

When I suppress the error with // @ts-ignore, everything is working fine. Please tell me how to get resolve this error.


Solution

  • Make sure that you are using Screen type form @testing-library/react. There is a Screen type in lib.dom.d.ts and it is resolved by tsconfig