TypeScript/React Testing: Components, Hooks, Custom Hooks, Redux and Zustand

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ย. 2024

ความคิดเห็น • 164

  • @pfcosta84
    @pfcosta84 3 ปีที่แล้ว +35

    I'm really amazed by the quality of each video that you've uploaded so far. I've basically shared them all with my colleagues.
    Given that you're introducing in BS/TS some design patterns and in this next premiere you're talking about Zustand, could we have a mix of both worlds?
    For instance, how to perform undo/redo operations using a command/memento pattern mixed with a state management library? Again, keep those videos coming! Really amazing stuff!

    • @jherr
      @jherr  3 ปีที่แล้ว +4

      I like how you think Pedro! That video sounds like a fun one!

    • @danielflorencio9661
      @danielflorencio9661 ปีที่แล้ว

      Hey Pedro, are you Brazilian? I'm looking for a Dev job, lol

  • @curiousprogrammer90
    @curiousprogrammer90 3 ปีที่แล้ว +11

    More on testing react and testing library please! :) Thanks for this!

  • @danvacari5744
    @danvacari5744 ปีที่แล้ว +1

    You actually do not pronounce "Zustand" correctly, albeit you insist throughout the video in doing so numerous times 😀. Nevertheless, great content, i have recently started researching how to test my code, and, surprisingly, the web is very scarce in terms of good quality info on testing. Keep up the great work !

  • @herubond3610
    @herubond3610 3 ปีที่แล้ว +6

    I really like the way you teaching about React and TypeSctipt stuff!!

    • @jherr
      @jherr  3 ปีที่แล้ว

      Thanks!

  • @skv1991
    @skv1991 ปีที่แล้ว

    Why so many people use useCallback wrapper for functions in simple components?
    Most of the time it's unuseful, it creates function, initialize additional array of dependencies and adds memoizing.
    This looks weird to optimize so simple functions (yes, components are just function)
    So if component re-renders, it always create new function no matter of using useCallback, because your function will passed as callback to useCallback hook params, and recreates its instance only if dependencies changed, but, most of the time, useCallback with simple function as callback without dependencies works same as if you create just this new function without wrapping in useCallback. No profit here.
    The profit is when you have more complex app with memo around components, useMemo for complex computation etc.
    In common cases, using of useCallback is meaningless. It's pre-optimization, which creates additional entities (array, function, watchers etc) instead of just one function

  • @chaboxx159c
    @chaboxx159c 2 ปีที่แล้ว +2

    thanks man ur really awesome

  • @ngneerin
    @ngneerin 3 ปีที่แล้ว +4

    We need NodeJS+Typescript Testing

  • @ponderatulify
    @ponderatulify 2 ปีที่แล้ว +1

    You just love pronouncing zuStand :))

  • @andyazma4198
    @andyazma4198 2 ปีที่แล้ว +1

    Thanks a lot, it's amazing video :)

  • @parushanaidoo9183
    @parushanaidoo9183 ปีที่แล้ว +1

    Thank you for this tutortial. It really helps

  • @carefree_ladka
    @carefree_ladka 2 ปีที่แล้ว +1

    await waitfor can by replaced by findBy*

  • @muzamilahmed6396
    @muzamilahmed6396 2 ปีที่แล้ว +2

    Hi Jack, Thank you so much for your tutorials. I would request you add a tutorial for material UI react testing. Thanks!

  • @aghileslounis
    @aghileslounis 2 ปีที่แล้ว +2

    You are just so good ! I consider myself like a Mid level developer with 3yrs of exp but you are just on another level, first time i see on youtube a true Senior/Lead or even higher I don't know whats above that lol, you inspire me to become better on every video you make, thanks for your great effort.
    In addition to that I want to know what's your opinion about the "Outside In tdd" and "Inside out tdd" what approach is better if there is one ?

  • @mehmetsayn573
    @mehmetsayn573 2 ปีที่แล้ว +1

    Everything in nutshell. Thanks

  • @mycovearomany455
    @mycovearomany455 ปีที่แล้ว +2

    Thanks for this really nice video with practical examples.
    Testing React Context API would be great if included

  • @EduardoYudjiNagashimaMiyata
    @EduardoYudjiNagashimaMiyata 10 หลายเดือนก่อน +2

    Even after two years, it is very current, congratulations!

  • @samuelvalentine7846
    @samuelvalentine7846 2 ปีที่แล้ว +3

    Wow 👏, this is really no BS..ad free, straight to the point 👏

  • @ImranKhansilvake
    @ImranKhansilvake ปีที่แล้ว +1

    very nice. Thanks for the video

  • @luislla3142
    @luislla3142 2 ปีที่แล้ว +2

    Hello, let me show my gratitude, thanks so much for such an amazing job, quite practical aproach. Please continue doing videos like this.

  • @sumanmarahatha4274
    @sumanmarahatha4274 3 ปีที่แล้ว +2

    Needed full series on react testing library with jest

  • @letok2871
    @letok2871 2 ปีที่แล้ว +2

    I am angular developer which start explore react js, and I am consider your videos the most informative. Thank you for your content!!

  • @dailymeow3283
    @dailymeow3283 3 ปีที่แล้ว +2

    Lol i like the thumbnail 🤭🤭

  • @ajinkyax
    @ajinkyax 2 ปีที่แล้ว

    With new updates waitForNextUpdate is not needed, since react testing lib this function in-built now.
    import { renderHook, act } from '@testing-library/react'
    const { result } = renderHook(() => useCustomHook({ userId }))
    act(() => result.current.login())
    expect(result.current.hasLoggedIn).toEqual(true)

  • @eisanodehi
    @eisanodehi 2 ปีที่แล้ว +1

    Great quality in everything. Thank you a lot. My youtube sidebar is all dedicated to Jack Herrington tho I'm watching them all the time.

  • @amitsinghrawat4760
    @amitsinghrawat4760 3 ปีที่แล้ว +2

    Hi Jack, can you make a video tutorial on sorting react import automatically

  • @ByteBurstWithBob
    @ByteBurstWithBob 8 หลายเดือนก่อน

    An update for the API hook testing:
    test("useAPI hook", async () => {
    jest.spyOn(global, "fetch").mockImplementation(() =>
    Promise.resolve({
    ok: true,
    json: () => Promise.resolve({ name: "Ebrahim" }),
    })
    );
    const { result } = renderHook(() => useAPI());
    await waitFor(() => expect(result.current).toEqual({ name: "Ebrahim" }));
    });

  • @MrRobeezy29
    @MrRobeezy29 2 ปีที่แล้ว +1

    what is the typeahead extension that you're using to autocomplete the line of code before it's been written?

    • @jherr
      @jherr  2 ปีที่แล้ว

      GitHub Copilot,

  • @mani8586
    @mani8586 3 ปีที่แล้ว +2

    Hi Jack, can we have a session on Redux Saga...

  • @joraanbe
    @joraanbe 2 ปีที่แล้ว +1

    Amazing and very very complete video, and is short!!! Thanks for sharing !!

  • @tarunsukhu2614
    @tarunsukhu2614 3 ปีที่แล้ว +2

    As usual Gold Standard video. I still re-run your videos for refreshing older topics I may have not touched for a while. Also nice French beard Jack :-)

    • @jherr
      @jherr  3 ปีที่แล้ว +1

      French beard, ok. Never heard that before, but I'll take it! 😀

  • @hameedhameed5542
    @hameedhameed5542 2 ปีที่แล้ว +2

    This is just awesome. With your help, I have a good grasp of what testing is.

  • @khudadadrasikh
    @khudadadrasikh 2 ปีที่แล้ว +1

    I found it very helpful. Thank you Jack Herrington

  • @lawrencejones51
    @lawrencejones51 ปีที่แล้ว +1

    Very nice video. My background is TDD since 2000 so its nice to see how to implement this paradigm in React (with different supporting libraries). Thanks so much!

  • @victorbadaro
    @victorbadaro 2 ปีที่แล้ว +1

    wow man... what a video!

  • @sheikmunavarbasha5535
    @sheikmunavarbasha5535 ปีที่แล้ว

    Property 'waitForNextUpdate' does not exist on type 'RenderHookResult'.ts(2339)
    What's the alternative to it?

  • @BSK_Rick
    @BSK_Rick ปีที่แล้ว +1

    Hey, Jack, thank you so much for that, i was try to test my hooks and well, this video make it so simple!

  • @gerardsiles
    @gerardsiles ปีที่แล้ว

    I'm getting this error: App.test.js: Support for the experimental sy
    ntax 'jsx' isn't currently enabled

  • @sandradivan2728
    @sandradivan2728 ปีที่แล้ว +1

    Hi Jack!
    I love all your videos; you speak very clearly, and I can understand almost everything you say.
    I would appreciate it if you could make a video explaining how to test functions that are inside a React component (and are not received via props) using mocks. Additionally, it would be great if you could demonstrate how to test different renders that result from useState changes within a functional component.
    Thank you very much! Greetings from Argentina! =)

  • @antonioteixeira1779
    @antonioteixeira1779 7 หลายเดือนก่อน +1

    Awesome, thank you from Brazil!

  • @lalitkandpal1483
    @lalitkandpal1483 2 ปีที่แล้ว +1

    How can i write a test for hook passed by props in component and pass setHook in test

    • @jherr
      @jherr  2 ปีที่แล้ว

      You test the component and that should test the hook.

  • @amajuify
    @amajuify ปีที่แล้ว

    Great content Jack. Is there a way to test the flow of a custom hook that dispatches redux actions? I'm asking this because redux-saga was introduced to a new project i'm working on by a senior developer that newly joined the team, and the selling point was we can test the flow of a side-effect using redux-saga as opposed to a custom react hook where we can't test the flow.
    During my research about redux-saga, I found that a lot of teams are moving away from it and the docs for it hasn't been updated. Would you recommend using redux-saga?

  • @mustafe1391
    @mustafe1391 2 ปีที่แล้ว +2

    Nothing but amazing content, you are doing great job! I have noticed myself skipping all other* tutorial stuff and always going to your videos. You are doing it right. Keep at it!

  • @keiji0075
    @keiji0075 2 ปีที่แล้ว +1

    more than best

  • @rival-slays
    @rival-slays 2 ปีที่แล้ว +1

    Blown away by the videos I’ve seen so far. No one is covering these more advanced topics as well as you do.
    What is the extension that gives you the test autocomplete btw? I was so impressed by how accurate it was.

  • @marvinotieno2194
    @marvinotieno2194 6 หลายเดือนก่อน

    Thanks for the video it's been really helpful. Could you also show how to test components that require the thunk middleware?

  • @mahu_4312
    @mahu_4312 3 ปีที่แล้ว +2

    Hello Jack, thank you very much for all your Tutorials.

    • @jherr
      @jherr  3 ปีที่แล้ว

      You are very welcome. Happy to have your views!

  • @mridulmishra8166
    @mridulmishra8166 2 ปีที่แล้ว +1

    Wow.. just wowww

  • @vittoriomorellini1939
    @vittoriomorellini1939 ปีที่แล้ว

    Is react-testing-library the right tool to make both integration test and e2e tests? this video was very cool and usefull. I downloaded the source. Thank you for sharing

  • @decentrob8126
    @decentrob8126 2 ปีที่แล้ว

    why you would use waitFor instead of findByRole (17:20)? Is there a difference?

  • @27sosite73
    @27sosite73 7 หลายเดือนก่อน +1

    thank you

  • @chauhan035
    @chauhan035 2 ปีที่แล้ว +1

    Awesome

  • @andriimuntian3632
    @andriimuntian3632 2 ปีที่แล้ว +1

    this is brilliant piece of knowledge you have shared here! Thank you!

  • @GoodHomeVideos
    @GoodHomeVideos ปีที่แล้ว

    I’d really like to know how to test a component that uses a ref on a HTML element. I’ve had so much trouble with this.

  • @anversadutt
    @anversadutt 3 ปีที่แล้ว

    who noticed that special effect at th-cam.com/video/bvdHVxqjv80/w-d-xo.html and Jack I learn a lot from your videos, pls keep em coming, thx

  • @edydflow5524
    @edydflow5524 ปีที่แล้ว

    I got error "a test was not wrapped in act(...)." event if I run it on act method. May be i have missed something? 🤣

  • @user-gs2zp3dm1v
    @user-gs2zp3dm1v ปีที่แล้ว +1

    thanks a ton

  • @Satender-cd7zu
    @Satender-cd7zu 6 หลายเดือนก่อน +1

    Thanks, you just solved my 3 hour work!

  • @anujupadhyay10
    @anujupadhyay10 ปีที่แล้ว +1

    10/10 😉

  • @adamwoolf9993
    @adamwoolf9993 2 ปีที่แล้ว +2

    this is fantastic. Well paced, clear and logical explanations. 100% quality teaching and nice to see that you enjoy it!

  • @soulos45
    @soulos45 ปีที่แล้ว +1

    Thanks!

  • @SajidAliSoftwareEngineer
    @SajidAliSoftwareEngineer 2 ปีที่แล้ว +1

    Jack really I dont have words for appreciation, awesome video, I learn about the react testing. I watch many videos but your video really clear my testing concepts.
    Thank you so much.

  • @Nonsense116
    @Nonsense116 ปีที่แล้ว

    Maybe it wasn't a thing when this video was released but I'm curious as to why you chose to use something like setup server instead of just mocking a return value for the get request

  • @Zechey
    @Zechey ปีที่แล้ว

    doesnt seem to work anymore, jest just throws "SyntaxError: Cannot use import statement outside a module"

  • @ralphlargo9728
    @ralphlargo9728 2 ปีที่แล้ว +1

    Thank you so much for this. This is exactly what i'm looking for

  • @nimapourmohammadi4854
    @nimapourmohammadi4854 ปีที่แล้ว +1

    Really Helpful and clean solutions. Thanks

  • @tomascarignano5002
    @tomascarignano5002 2 ปีที่แล้ว +1

    Yesssss

  • @shivashankar6043
    @shivashankar6043 3 ปีที่แล้ว +3

    Jack never failed to give awesome contents 👏

  • @boot-strapper
    @boot-strapper 3 ปีที่แล้ว +2

    Been using this a lot the last 2 weeks on my current project

    • @jherr
      @jherr  3 ปีที่แล้ว +1

      It's great, right? And MSW is super cool!

  • @sanazseifi5105
    @sanazseifi5105 2 ปีที่แล้ว +1

    Such a great tutorial! Awesome, thank you so much.

  • @Berkeli
    @Berkeli 2 ปีที่แล้ว +5

    The fact that the video only has 17k views makes me sad. Testing is so freaking cool and more people should be learning it. Excellent video

  • @aaronmcadam
    @aaronmcadam 3 ปีที่แล้ว +1

    This was really great! I’ve bought the book, thanks! ❤️

  • @FragmentFrontDeveloper
    @FragmentFrontDeveloper ปีที่แล้ว

    That was great. Please add example when add axios or wrap axios to custom method.

  • @CameronRounder
    @CameronRounder 3 ปีที่แล้ว +1

    I've read the "isMounted" variable doesn't actually prevent against memory leaks, which is the end goal of the flag and preventing setData() from getting called. I've also seen first handed MSW library cause memory leaks in tests. Is there a reason to use MSW over nock or some other mocking framework over MSW - specific features??

    • @jherr
      @jherr  3 ปีที่แล้ว +2

      I haven't seen MSW leaks, but that doesn't mean they don't exist. The value to me of MSW is that it's the lightest possible touch in terms of mocking. Outside of just running MSW there is no change to the production code.
      As for isMounted, I'm not using it to protect against memory leaks but instead ensuring that we don't get React complaining about setting state after the component is unmounted, which is pretty easy to repro.
      Thanks for the great comments!

  • @thatWebGuySolutions
    @thatWebGuySolutions ปีที่แล้ว

    Great stuff! Is fireEvent better than user? Also for orgState why not grab current state before each test?

  • @ahmedsoran4710
    @ahmedsoran4710 ปีที่แล้ว

    thank you for this great tutorial but im confused why we need to waste a huge time writing testing code when you can use console log and see results?!

  • @nattysweg343
    @nattysweg343 ปีที่แล้ว +1

    Feels like I have been consuming content for years to stumble upon this gem

  • @rahulsriram6295
    @rahulsriram6295 3 ปีที่แล้ว +1

    Jack I've heard that if you premiere a video on TH-cam, right after the premiere in done, for 1 hours, views won't be counted. Please confirm on that

    • @jherr
      @jherr  3 ปีที่แล้ว

      That sounds bad. I haven't heard that. I can't imagine why that would be the case, but maybe it is.

  • @bscodev
    @bscodev 3 ปีที่แล้ว +1

    Thanks best content of react and typescript!

  • @yasin_osman
    @yasin_osman 3 ปีที่แล้ว +1

    Thank you so much for your amazing content, i really would like to see your channel growing. Keep up the good work 👏👏👏

  • @wesleyhandy7528
    @wesleyhandy7528 3 ปีที่แล้ว +1

    The async testing of react-hooks was helpful. What is the benefit between running a mock server/service worker vs mocking fetch or mocking a method that calls fetch with a mockResolveValue? I suppose running the server means you don't need to mock fetch, which is quite helpful. Often, I extract my api calls from components, and I can mock the method that makes the call. Is it just six of one, half a dozen of the other, or maybe letting fetch do its thing against a mock server is preferable. Thanks.

    • @jherr
      @jherr  3 ปีที่แล้ว

      I think you hit it at the end there. Basically letting fetch and the rest of the code do its thing but basically sandbox it so that it's talking to the mock service instead of the real deal.

  • @manantank
    @manantank 2 ปีที่แล้ว +2

    This is such a good tutorial for testing. Thank you for your amazing work!

  • @rajankhunt7002
    @rajankhunt7002 ปีที่แล้ว

    Please you make your video slow so, we can more focus on and your videos is so great but this one is issue.

  • @devsami
    @devsami 9 หลายเดือนก่อน

    Just a quick question do we need a ts-jest transformer ?

  • @iqwebserve3973
    @iqwebserve3973 ปีที่แล้ว +1

    Excellent for newbies and as a refresher! Thanks!

  • @miguelship3
    @miguelship3 2 ปีที่แล้ว

    Do you have a video for testing an rtk query endpoint?

  • @tsooooooo
    @tsooooooo 2 ปีที่แล้ว +1

    No BS TS is such a good title for the book!

  • @fotios4902
    @fotios4902 2 ปีที่แล้ว +1

    Thanks for the awesome tutorial!

  • @murtazasalim7572
    @murtazasalim7572 2 ปีที่แล้ว +1

    awesome explanation and methodology
    .

  • @HotRatsAndTheStooges
    @HotRatsAndTheStooges 2 ปีที่แล้ว +1

    Really nice video, thanks a lot! Covers a lot in a really easy to digest format

  • @herbertpimentel
    @herbertpimentel 3 ปีที่แล้ว +1

    OMG 😍 thank you... Again.

  • @MrKeepItTrill
    @MrKeepItTrill 2 ปีที่แล้ว +1

    Great video! Is there any meaningful difference between resetting the Zustand store on beforeEach vs afterEach?

    • @jherr
      @jherr  2 ปีที่แล้ว

      I don't think so.

  • @donotthink
    @donotthink 2 ปีที่แล้ว +1

    This here is quality content! Thank you!

  • @LoryKa
    @LoryKa 2 ปีที่แล้ว

    13:30 : why "count is 0" not true, since we clicked the element only after getting the value of divElement, therefore the divElement should be still 0 and not 1.
    I tried something similar in my application: I tried to test whether the counter is increasing after we press the "+", therefore I got the span's value, stored it in value1, fired a user event, stored the second value in value2, and check whether value2 > value1 and the test passed. Could you please explain why is this difference?

    • @LoryKa
      @LoryKa 2 ปีที่แล้ว

      My bad, I was storing the .textContent property of the span element, and not the actual span element. Since the span element is an object, if you access the textContent property after the fire event it's gonna show the new value

  • @amphetaminocid
    @amphetaminocid 2 ปีที่แล้ว +1

    Please keep up. This video is awesome.

  • @techworld3043
    @techworld3043 3 ปีที่แล้ว +1

    nice thumbnail. jacky

  • @matthewrideout426
    @matthewrideout426 ปีที่แล้ว

    Struggling to mock my zustand store and I thought I wonder if jack herrington will have a video on this. Bingo. What a guy. Thanks Jacky baby

  • @SyedZainUlHasan
    @SyedZainUlHasan 2 ปีที่แล้ว +1

    Really nice lecture Jack. How we can test components with tables?

    • @jherr
      @jherr  2 ปีที่แล้ว

      Feel free to jump on the Discord server discord.gg/eJ5bYFb6 and post a question in the #react channel. That being said please read the #rules first and make sure that you post a succinct question that is answerable by the volunteers on the server.

  • @chauhan035
    @chauhan035 2 ปีที่แล้ว +1

    How snapshot is different from this one ?

    • @jherr
      @jherr  2 ปีที่แล้ว +1

      Snapshots get all the attributes indiscriminately. There is no indication of what parts of it are important, and what are not, nor any indication of what you are testing.

    • @chauhan035
      @chauhan035 2 ปีที่แล้ว

      @@jherr okay thanks 😊

  • @bafian
    @bafian 2 ปีที่แล้ว +1

    great content as always, loved zustand.

  • @ReQ1964SPA-vu4xu
    @ReQ1964SPA-vu4xu 17 วันที่ผ่านมา

    You're a lifesaver man!