react-testing-library icon indicating copy to clipboard operation
react-testing-library copied to clipboard

@types/testing-library__react"' has no exported member 'waitFor'

Open denchen opened this issue 6 years ago • 31 comments

  • @testing-library/react version: 10.0.0
  • react version: 16.13.0
  • node version: 12.13.0
  • npm (or yarn) version: 1.21.1

Relevant code or config:

import {  waitFor } from '@testing-library/react';

What happened:

I get a typescript error:

@types/testing-library__react"' has no exported member 'waitFor'.ts(2305)

Reproduction:

I have @testing-library/react@^10.0.0 and @types/testing-library__react@^9.1.3 installed. I believe each is the latest version.

My current workaround is to add // @ts-nocheck to get my test with waitFor() to pass.

denchen avatar Mar 13 '20 01:03 denchen

This will be fixed as soon as this is merged: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43102 😁

kentcdodds avatar Mar 13 '20 02:03 kentcdodds

@kentcdodds it might be better to close issues once they are actually resolved. Open issues have a better visibility for others encountering the same problem

bbrinx avatar Mar 17 '20 15:03 bbrinx

You're not wrong, but I like to only keep issues open for as long as they have action items we can take within the project where they are. It helps keep things organized.

kentcdodds avatar Mar 17 '20 15:03 kentcdodds

I'm still getting this issue using @testing-library/[email protected]

Dobby89 avatar Mar 23 '20 12:03 Dobby89

Me too. @kentcdodds Could you please reopen this issue?

tom-sherman avatar Mar 23 '20 15:03 tom-sherman

We have to bump our dependency on @types/testing-library__react once https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43108 is merged. Re-opening since this requires action in this repository.

eps1lon avatar Mar 23 '20 15:03 eps1lon

@eps1lon Did you mean to re-open this?

--Edit: Nevermind, I needed to restart my typescript server with latest packages.

MattShrider avatar Apr 06 '20 15:04 MattShrider

i still having the same errors

roychoo avatar Apr 13 '20 11:04 roychoo

@roychoo, Hi, after I update @types/testing-libary__react to version 10.0.1, I still got the same error. Inside @types/testing-libary__react folder, the package.json file always reference to the @types/testing-libary__dom@* (the newest one). However, as I read my yarn.lock I saw @types/testing-libary__dom@* always point to the older version (6.0.1 for exp). So I think you may have this problem also. I think you need to modify your yarn.lock file. The solution I used was yarn add @types/[email protected]. This somehow fixed my issue. If not you can remove your node modules and re-install or maybe remove yarn.lock. Sr for my bad English.

huylocit14054 avatar Apr 15 '20 10:04 huylocit14054

@huylocit14054 Installing the types yourself is not an ideal solution IMO while @testing-library/dom already includes these as a dependency, there's a potential for them to get out of sync and cause weird errors. This is very much related to https://github.com/testing-library/react-testing-library/issues/620 and https://github.com/testing-library/dom-testing-library/issues/494

tom-sherman avatar Apr 15 '20 11:04 tom-sherman

@huylocit14054 Installing the types yourself is not an ideal solution IMO while @testing-library/dom already includes these as a dependency, there's a potential for them to get out of sync and cause weird errors. This is very much related to #620 and testing-library/dom-testing-library#494

@tom-sherman, you are totally correct. So as far as I understand, in my yarn.lock file, the version of @types/testing-library__dom@* is not the newest one as it should be. So I need to do something to update it to the newest version. After fixing my yarn.lock, I can remove @types/testing-library__dom without any problem. Thank you 👍.

huylocit14054 avatar Apr 15 '20 11:04 huylocit14054

Fixed with yarn remove @testing-library/react @testing-library/jest-dom && yarn add @testing-library/react @testing-library/jest-dom

nathanbirrell avatar Apr 17 '20 01:04 nathanbirrell

Fixed with npm uninstall @testing-library/react @testing-library/jest-dom && npm install --save-dev @testing-library/react @testing-library/jest-dom

panpan-lin avatar Apr 19 '20 22:04 panpan-lin

    "@testing-library/react": "10.0.5",
    "@testing-library/jest-dom": "5.9.0",
    "react": "16.13.1",

I still get the same error. I've tried all solutions mentioned in this issue, and none helps.

matassp avatar Jun 03 '20 06:06 matassp

@matassp what version of @testing-library/dom is in your yarn.lock or package-lock.json?

samtsai avatar Jun 03 '20 13:06 samtsai

Fixed with yarn remove @testing-library/react @testing-library/jest-dom && yarn add @testing-library/react @testing-library/jest-dom

This fixed my issue with the tests:

...node_modules/@types/testing-library__react"' has no exported member 'screen'

I went from:

"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",

to:

"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^10.4.9",

For the sake of completion I created my app with CRA from npx and I got the following React version: v16.13.1

Which apparently does not include the proper version of those dependencies to use screen from testing-library/react.

But now I got the following error when running my app:

node_modules/@testing-library/dom/node_modules/pretty-format/build/index.d.ts(7,13):
'=' expected.  TS1005

     5 |  * LICENSE file in the root directory of this source tree.
     6 |  */
  >  7 | import type * as PrettyFormat from './types';
       |             ^
     8 | /**
     9 |  * Returns a presentation string of your `val` object
    10 |  * @param val any potential JavaScript object

So I am rolling back...

gugol2 avatar Aug 23 '20 11:08 gugol2

Make sure you're using at least TypeScript 3.8, it's required for import type.

nickserv avatar Aug 25 '20 04:08 nickserv

Make sure you're using at least TypeScript 3.8, it's required for import type.

As I said when building my app I run npx CRA with the typescript template flag... (npx should give me the latest stable, right?)

And it landed with a package.json with:

"typescript": "~3.7.2"

I prefer to rollback and not touch too much what CRA gave me, so I am just descructuring the output of render.

gugol2 avatar Aug 25 '20 08:08 gugol2

What's the exact version of TypeScript you have installed?

nickserv avatar Aug 25 '20 16:08 nickserv

~ means the latest patch, so it would never reach 3.8.x ^ meas latest minor or patch version, so if I had the caret symbol it could potentially install the 3.8.x

Anyway my version is 3.7.5

gugol2 avatar Aug 25 '20 18:08 gugol2