Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
denchen opened this issue Mar 13, 2020 · 31 comments
Closed

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

denchen opened this issue Mar 13, 2020 · 31 comments

Comments

@denchen
Copy link

denchen commented Mar 13, 2020

  • @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.

@kentcdodds
Copy link
Member

This will be fixed as soon as this is merged: DefinitelyTyped/DefinitelyTyped#43102 😁

@bbrinx
Copy link

bbrinx commented Mar 17, 2020

@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

@kentcdodds
Copy link
Member

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.

@Dobby89
Copy link

Dobby89 commented Mar 23, 2020

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

@tom-sherman
Copy link

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

@eps1lon
Copy link
Member

eps1lon commented Mar 23, 2020

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

@MattShrider
Copy link

MattShrider commented Apr 6, 2020

@eps1lon Did you mean to re-open this?

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

@roychoo
Copy link

roychoo commented Apr 13, 2020

i still having the same errors

@huylocit14054
Copy link

huylocit14054 commented Apr 15, 2020

@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.

m7kvqbe1 added a commit to Royal-Navy/design-system that referenced this issue Apr 15, 2020
m7kvqbe1 added a commit to Royal-Navy/design-system that referenced this issue Apr 15, 2020
@tom-sherman
Copy link

@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

@huylocit14054
Copy link

@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 👍.

@nathanbirrell
Copy link

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

@panpan-lin
Copy link

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

@matassp
Copy link

matassp commented Jun 3, 2020

    "@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.

@samtsai
Copy link
Collaborator

samtsai commented Jun 3, 2020

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

@gugol2
Copy link

gugol2 commented Aug 23, 2020

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

@nickserv
Copy link
Member

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

@gugol2
Copy link

gugol2 commented Aug 25, 2020

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.

@nickserv
Copy link
Member

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

@gugol2
Copy link

gugol2 commented Aug 25, 2020

~ 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

@nickserv
Copy link
Member

nickserv commented Aug 26, 2020

You'll need something like ^3.7.2 or ~3.8.0. to install at least TypeScript 3.8

@gugol2
Copy link

gugol2 commented Aug 26, 2020

I know... and as I already SAID I used npx CRA with the ts template...

I am not going to upgrade @testing-library/react @testing-library/jest-dom and typescript.

All the dependencies should be fine out of the box.
So I will manage without screen.

Thanks!

@fire-cracker
Copy link

@gugol2 I have exactly the same issues.

th3mon added a commit to th3mon/course-price-calculator that referenced this issue Oct 2, 2020
I had some issues with React Testing Library for TS
testing-library/react-testing-library#610
@gugol2
Copy link

gugol2 commented Oct 3, 2020

@gugol2 I have exactly the same issues.

Well, I took that approach at that time.
I don't know if running CRA with npx keeps locking the dependencies just the same today, it's been some time...

Sorry I just checked, last release of CRA is 3.4.1 (2020-03-20)
So I guess it must be the same with a fresh project.

I don't find it that painful to just destructure the output of render.

@jose920405
Copy link

jose920405 commented Oct 5, 2020

For new react projects still happening. With last versions of everything.

@nickserv
Copy link
Member

nickserv commented Oct 5, 2020

I believe CRA 4 will fix this

@RichMatthews
Copy link

still getting this issue

@kentcdodds
Copy link
Member

CRA 4 hasn't been released yet. Update your version of @testing-library/react

@gugol2
Copy link

gugol2 commented Oct 22, 2020

CRA 4 hasn't been released yet. Update your version of @testing-library/react

@kentcdodds it is not only about RTL, it complains about other dependencies too...

#610 (comment)

I tried but in the end I rolled back, IMHO it is not so much pain to just destructure the output of render.

@gugol2
Copy link

gugol2 commented Oct 24, 2020

Now CRA 4 is here!!!

https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md#400-2020-10-23

"To infinity.... and Beyond"

@elioenays
Copy link

@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.

I solved my problem with that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests