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

Move testHook to its own pacakge #302

Closed
kentcdodds opened this issue Feb 16, 2019 · 31 comments
Closed

Move testHook to its own pacakge #302

kentcdodds opened this issue Feb 16, 2019 · 31 comments
Labels
BREAKING CHANGE This change will require a major version bump released

Comments

@kentcdodds
Copy link
Member

It seems to be causing a lot of confusion for people and we definitely don't want application developers using it to "unit test" their hooks. Putting it into another package would make it easier for us to call out its true purpose and reduce the chance of misuse.

Thoughts?

@kentcdodds kentcdodds added the BREAKING CHANGE This change will require a major version bump label Feb 16, 2019
@donavon
Copy link
Contributor

donavon commented Feb 16, 2019

I'm all for this

https://twitter.com/donavon/status/1096061809499561984

react-hooks-testing-library?

@kentcdodds
Copy link
Member Author

You make it, and I'll make this happen

@ooade
Copy link

ooade commented Feb 16, 2019

Yeah 🤸

@donavon
Copy link
Contributor

donavon commented Feb 16, 2019

I have some family obligations today, but will get on this as soon as I can. But go out and grab the npm name

@donavon
Copy link
Contributor

donavon commented Feb 16, 2019

@kentcdodds
Copy link
Member Author

Oh cool! Could you give it a look and open an issue for anything that's lacking/different and see if the maintainer is interested in doing/accepting what we need?

@alexkrolick
Copy link
Collaborator

alexkrolick commented Feb 16, 2019

Putting it into another package would make it easier for us to call out its true purpose and reduce the chance of misuse.

Well, we also pulled a Webpack and released with no docs. I think this is pretty prominently explained in the docs PR for testHook: testing-library/testing-library-docs#32

The linked package seems pretty close in API - I'll file an issue since you both are indisposed.

@mpeyper
Copy link
Member

mpeyper commented Feb 17, 2019

Hey, author of react-hooks-testing-library here.

I started out with a "what would react-testing-library do" mentality so I'm not surprised that API is pretty close.

As I said in the other issue, it started out as a proof-of-concept from my perspective and I only updated it recently to match the stable hooks API in case anyone was actually using it. I've had a few thoughts on how the API could be improved, but nothing nailed down. I'm more than happy to accept PRs bringing it inline with any features offered by testHook (at a quick glance it's pretty much on par), or even for large breaking changes.

@mpeyper
Copy link
Member

mpeyper commented Feb 21, 2019

Just wanted to let you all know that I have published a testHook compatible version of react-hooks-testing-library (v0.3.2 is the current version in NPM).

@kentcdodds
Copy link
Member Author

Awesome. I think we're ready to make this happen. Anyone want to make the PR too remove testHook?

@schettino
Copy link
Contributor

I can handle this. :)

kentcdodds pushed a commit that referenced this issue Feb 24, 2019
This removes testHook in favor of http://npm.im/react-hook-testing-library

Closes #302

BREAKING CHANGE: move testHook to another library. Use http://npm.im/react-hook-testing-library instead
@kentcdodds
Copy link
Member Author

🎉 This issue has been resolved in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@danielkcz
Copy link
Contributor

danielkcz commented Feb 24, 2019

Oh wow, that was fast. Just a couple of days ago I was contributing to testHook and now it's gone elsewhere 😮

Can someone please enlighten me why it happened? Yes, I see the tweet and I still don't get it :)

When someone puts an effort into separating logic into a custom hook, I don't see why it should be bad being able to test it. It has a name and a clear purpose.

I am kinda sad there wasn't more discussion about this.

@kentcdodds
Copy link
Member Author

It has a name and a clear purpose.

You may think that its purpose is clear, but in the few days it existed we already saw people mistreating it. Custom hooks are implementation details 95% of the time.

It's not all that hard for library authors to install react-hook-testing-library.

@danielkcz
Copy link
Contributor

It's not all that hard for library authors to install react-hook-testing-library.

I know it's not hard. And that's why I am wondering how will that stop the actual "mistreat" of hooks? :) Feels like you have just dropped a slight detour on the road, but the destination is still the same ;)

@kentcdodds
Copy link
Member Author

Trust me, the detour is enough.

@danielkcz
Copy link
Contributor

danielkcz commented Feb 24, 2019

Sure, trust is a nice thing :) But for me, I am going to install that detour to the app (not library) and just use it because it's helpful. I don't think it's correct to say, that all hooks are an implementation detail. I have plenty of hooks that are reusable just within the app code.

@smmoosavi
Copy link

not found

package 'react-hook-testing-library' not found

https://www.npmjs.com/package/react-hook-testing-library

www npmjs com_package_react-hook-testing-library galaxy s5

@schettino
Copy link
Contributor

@smmoosavi
Copy link

smmoosavi commented Feb 24, 2019

There is the same mistake in the release page
https://github.com/kentcdodds/react-testing-library/releases/tag/v6.0.0

@danielkcz
Copy link
Contributor

danielkcz commented Feb 24, 2019

Btw, how will library authors find out about that package? Is it going to be in the docs? I don't expect people studying release notes :) If that's the case, how is it going to prevent claimed misuse by other people? If it's not going to be mentioned anywhere, library authors will just stitch together some custom solution so it's all for nothing.

I don't know, it's a strangely controversial decision. Instead of teaching people how to do things properly we try to hide things from them and hope for the best. No, I don't see it, really.

@alexkrolick
Copy link
Collaborator

alexkrolick commented Feb 24, 2019

@FredyC I'd hope we could move these WIP docs and examples onto an ecosystem page like user-event and jest-dom:

testing-library/testing-library-docs#32

cc @mpeyper

@danielkcz
Copy link
Contributor

danielkcz commented Feb 24, 2019

@alexkrolick Ok sure, but I am still kinda missing a whole reason why this was done. If it's going to be documented in official docs, how is that going to prevent anyone from abusing it? The focus should be really on teaching correct patterns and not moving things around just to make it interesting 😄

@kentcdodds It's not like it's going to get reverted, I get that. I just kinda want to understand how hiding, but not really hiding things can achieve smarter tests 💭

@kentcdodds
Copy link
Member Author

It's all got to do with inertia. when doing the wrong thing is really easy then more people do the wrong thing. But when it takes even a little bit extra effort to do the wrong thing then the only people willing to put forth the effort are the people who actually are doing it because it's the right thing to do.

@danielkcz
Copy link
Contributor

I see, thanks. Although in this case, it feels like that much bigger inertia comes with testing hooks without any utility than installing an extra package 😎

@jdav-dev
Copy link

jdav-dev commented Mar 9, 2019

@donavon When you get a chance, you should update your blog post Intro to React Hooks to reflect this move.

@tomstuart tomstuart mentioned this issue Jun 15, 2019
4 tasks
@kripod
Copy link

kripod commented Jun 15, 2019

Is it possible to move react-hooks-testing-library under the @testing-library scope? I think it would be more appealing and discoverable.

@kentcdodds
Copy link
Member Author

There's an open issue on that repo to do this. I want it 👍

@mpeyper
Copy link
Member

mpeyper commented Jun 17, 2019

@kentcdodds I'm all for moving react-hooks-testing-library to @testing-library/react-hooks 👍

How do we make this happen? I'm assuming this means moving the repo from mpeyper to the testing-library org, renaming the package and publishing it to the @testing-library npm scope, but I'm unsure how permissions and things work for all these things as I've never not owned the orgs/scopes myself for my libraries before.

@kentcdodds
Copy link
Member Author

Hey @mpeyper! That's great! I'll get you all the permissions set up. You'll need to accept the invitations which will be sent to you shortly.

If it's helpful, you can watch me do this for react,dom,cypress-testing-library on the video linked here: testing-library/dom-testing-library#260 (comment)

Thanks!

@kentcdodds
Copy link
Member Author

I thought this issue existed already, but it didn't. I apologize for not send you this earlier. Good luck! testing-library/react-hooks-testing-library#99

lucbpz pushed a commit to lucbpz/react-testing-library that referenced this issue Jul 26, 2020
@mpeyper mpeyper mentioned this issue Nov 11, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE This change will require a major version bump released
Projects
None yet
Development

No branches or pull requests

10 participants