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

Tests #101

Open
30 of 34 tasks
streamich opened this issue Feb 7, 2019 · 13 comments
Open
30 of 34 tasks

Tests #101

streamich opened this issue Feb 7, 2019 · 13 comments
Assignees
Labels
enhancement New feature or request
Projects

Comments

@streamich
Copy link
Owner

streamich commented Feb 7, 2019

  • Start adding unit tests for hooks.
  • What are the best practices for testing React Hooks?

Pending tests to be added

  • State block
    • createMemo
    • createReducer
    • useBoolean
    • useCounter
    • useNumber
    • useGetSet
    • useGetSetState
    • useList
    • useMap
    • useObservable
    • usePrevious
    • useSetState
    • useToggle
    • useDefault
  • Animation block
    • useRaf
    • useSpring
    • useTimeout
    • useTween
    • useUpdate
    • useTimeoutFn
    • useInterval
  • Lifecycle block
    • useDeepCompareEffect
    • useEffectOnce
    • useIsomorphicLayoutEffect
    • useLifecycles
    • useLogger
    • useMount
    • useMountedState
    • usePromise
    • useRefMounted
    • useUnmount
    • useUpdateEffect
@lvl99
Copy link
Contributor

lvl99 commented Mar 20, 2019

I've been using react-hooks-testing-library which seems pretty good so far.

@lvl99
Copy link
Contributor

lvl99 commented Mar 20, 2019

When I was testing some async hooks I wasn't able to adequately get around the act() error messages from generating. I know with CI=true on create-react-app that these messages can prevent a build pipeline from succeeding, even if the tests themselves passed.

@streamich streamich added this to To do in react-use via automation Mar 26, 2019
@ZWkang
Copy link

ZWkang commented Mar 30, 2019

pick the test tools and make a test branch start it.

@wardoost wardoost added the enhancement New feature or request label Mar 31, 2019
@ankithkonda
Copy link
Contributor

Please see pull request #221 :) let me know what you guys think

@Belco90
Copy link
Contributor

Belco90 commented Jul 16, 2019

Can I help with this? I love this collection of hooks and I like adding tests so I'm more than happy to help with this.

I've written tests for hooks before just with react-testing-library by creating a fake component within the test itself, but react-hooks-testing-library is another good option (which basically do the same: wrap the hook into a fake component and return the results).

I've seen some tests already added by @ankithkonda so the set up and the structure is already defined, I can add more tests following same pattern.

@streamich
Copy link
Owner Author

@Belco90 that is very very welcome!

@streamich streamich moved this from To do to In progress in react-use Jul 16, 2019
@Belco90
Copy link
Contributor

Belco90 commented Jul 17, 2019

Ok so my idea is to add tests for all hooks section by section on storybook (animation, lifecycle, state, etc) and create a PR for each of those sections. Does that make sense for you? I'll start from animation section since it already has some tests and are simple to be tested.

@streamich
Copy link
Owner Author

Does that make sense for you?

@Belco90 Yes, it does.

@Belco90
Copy link
Contributor

Belco90 commented Aug 2, 2019

It took me longer as expected as I was on holidays, but PR for first block of tests ready! #500

@Belco90
Copy link
Contributor

Belco90 commented Aug 22, 2019

Second block of tests ready! #554

From now on I'll keep adding tests by blocks but I'll create a PR for each hook test, so 1) I avoid re-doing tests done by someone else while I create my PR, 2) I have my branches up to date and I don't have to keep it updated with master, and 3) I can merge bug fixes asap if I found any issue while testing.

@Belco90
Copy link
Contributor

Belco90 commented Aug 27, 2019

@streamich I've edited your description to use it as pending hooks and blocks I need to test.

@gerardkabre
Copy link

I don't know if you plan to keep the conversation about tests in this issue but just in case, just created a PR adding tests for useWindowScroll: #1183 following the same style @ankithkonda used for useWindowSize.

@Belco90
Copy link
Contributor

Belco90 commented May 1, 2020

@gerardkabre Sorry but I can't continue adding tests here since I've been really busy lately. However, I think I added a nice bunch of tests here to get a solid base to keep testing other hooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
react-use
  
In progress
Development

No branches or pull requests

7 participants