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

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • By viewer request we are looking at testing React TypeScript components all the way from render components, through components with state, asynchronous components, custom hooks, Redux and Zustand.
    No BS TS Book: no-bs-ts.myshopify.com/
    Code: github.com/jherr/ts-react-tes...
    00:00 Introduction
    00:47 Project Setup
    01:55 Basic component testing
    05:06 Multiple element testing
    08:22 Event handler testing
    11:51 Testing state hooks
    14:07 Testing async hooks
    17:56 Testing simple custom hooks
    19:53 Testing async custom hooks
    22:18 Testing Redux components
    26:19 Testing Zustand components
    29:03 Outroduction
    React Testing Library: testing-library.com/docs/reac...
    Mock Service Worker: mswjs.io/
    React Hooks Testing Library: github.com/testing-library/re...
    👉 What's my theme? Night Wolf [black]
    👉 What's that font? MonoLisa
    👉 Jack is also on the React Round Up podcast: devchat.tv/podcasts/react-rou...
    👉 Don't forget to subscribe to this channel for more updates: bit.ly/2E7drfJ
    👉 Discord server signup: / discord
    Thank you for watching this video, click the "SUBSCRIBE" button to stay connected with this channel.
    #typescript #nobsTS #testing #mockServiceWorker
  • Věda a technologie

Komentáře • 161

  • @idilenebrito6570
    @idilenebrito6570 Před rokem +1

    Simplesmente o melhor vídeo de testes que já assistir. Perfeito e com exemplos!

  • @mustafe1391
    @mustafe1391 Před 2 lety +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!

  • @adamwoolf9993
    @adamwoolf9993 Před rokem +2

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

  • @hameedhameed5542
    @hameedhameed5542 Před 2 lety +2

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

  • @curiousprogrammer90
    @curiousprogrammer90 Před 2 lety +11

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

  • @SajidAliSoftwareEngineer
    @SajidAliSoftwareEngineer Před 2 lety +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.

  • @JC-yy5nf
    @JC-yy5nf Před rokem

    Absolutely great tutorial (although a little outdate, but that's normal). Great, simple, to-the-point steps and explanations, great voice delivery, great enthusiasm. Thank you for making these!

  • @manantank
    @manantank Před 2 lety +2

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

  • @lawrencejones51
    @lawrencejones51 Před rokem +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!

  • @avinashvivek
    @avinashvivek Před rokem

    Thank you very much Jack, for posting this video.
    I was trying to understand react testing since last 3 days and finally came here.
    Now I am very much clear with React Testing (with typescript).
    Thanks again 🙂

  • @samuelvalentine7846
    @samuelvalentine7846 Před rokem +2

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

  • @luisespinosallanos3142
    @luisespinosallanos3142 Před 2 lety +2

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

  • @herubond3610
    @herubond3610 Před 2 lety +6

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

  • @HotRatsAndTheStooges
    @HotRatsAndTheStooges Před 2 lety +1

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

  • @yasin_osman
    @yasin_osman Před 2 lety +1

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

  • @EduardoYudjiNagashimaMiyata
    @EduardoYudjiNagashimaMiyata Před 8 měsíci +1

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

  • @andriimuntian3632
    @andriimuntian3632 Před 2 lety +1

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

  • @iqwebserve3973
    @iqwebserve3973 Před 11 měsíci +1

    Excellent for newbies and as a refresher! Thanks!

  • @aaronmcadam
    @aaronmcadam Před 2 lety +1

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

  • @letok2871
    @letok2871 Před 2 lety +2

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

  • @shivashankar6043
    @shivashankar6043 Před 2 lety +3

    Jack never failed to give awesome contents 👏

  • @joraanbe
    @joraanbe Před 2 lety +1

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

  • @nattysweg343
    @nattysweg343 Před rokem +1

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

  • @BSK_Rick
    @BSK_Rick Před rokem +1

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

  • @bafian
    @bafian Před 2 lety +1

    great content as always, loved zustand.

  • @tarunsukhu2614
    @tarunsukhu2614 Před 2 lety +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  Před 2 lety +1

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

  • @ralphlargo9728
    @ralphlargo9728 Před 2 lety +1

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

  • @mycovearomany455
    @mycovearomany455 Před rokem +2

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

  • @holdmybeaver
    @holdmybeaver Před 2 lety +1

    thank you, Jack, great content as always!

  • @sanazseifi5105
    @sanazseifi5105 Před rokem +1

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

  • @pfcosta84
    @pfcosta84 Před 2 lety +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  Před 2 lety +4

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

    • @danielflorencio9661
      @danielflorencio9661 Před rokem

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

  • @khudadadrasikh
    @khudadadrasikh Před 2 lety +1

    I found it very helpful. Thank you Jack Herrington

  • @worldhello4012
    @worldhello4012 Před rokem

    It's so clear to understand. appreciate you to make this video :)

  • @antonioteixeira1779
    @antonioteixeira1779 Před 5 měsíci +1

    Awesome, thank you from Brazil!

  • @mahu_4312
    @mahu_4312 Před 2 lety +1

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

    • @jherr
      @jherr  Před 2 lety

      You are very welcome. Happy to have your views!

  • @AlinaTudose
    @AlinaTudose Před 8 měsíci +1

    That was so clean and clear 😊

  • @nimapourmohammadi4854
    @nimapourmohammadi4854 Před rokem +1

    Really Helpful and clean solutions. Thanks

  • @donotthink
    @donotthink Před 2 lety +1

    This here is quality content! Thank you!

  • @Errorisedqt
    @Errorisedqt Před rokem

    Thank you for your amazing content. You cant believe how much i learned and i am looking forward to more of your content. :)

  • @fotios4902
    @fotios4902 Před 2 lety +1

    Thanks for the awesome tutorial!

  • @murtazasalim7572
    @murtazasalim7572 Před 2 lety +1

    awesome explanation and methodology
    .

  • @boot-strapper
    @boot-strapper Před 2 lety +2

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

    • @jherr
      @jherr  Před 2 lety +1

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

  • @sandradivan2728
    @sandradivan2728 Před rokem +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! =)

  • @Satender-cd7zu
    @Satender-cd7zu Před 4 měsíci +1

    Thanks, you just solved my 3 hour work!

  • @muzamilahmed6396
    @muzamilahmed6396 Před 2 lety +2

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

  • @parushanaidoo9183
    @parushanaidoo9183 Před rokem +1

    Thank you for this tutortial. It really helps

  • @tsooooooo
    @tsooooooo Před 2 lety +1

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

  • @alexanderleonardo5649
    @alexanderleonardo5649 Před 2 lety

    fast and easy to understand. thx

  • @rival-slays
    @rival-slays Před 2 lety +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.

  • @vittoriomorellini1939
    @vittoriomorellini1939 Před 11 měsíci

    This level of test is interesting, it is difficult to find such a deep level of test. This has to be the starting point to test deeply and with an acceptable code coverage a project quite complicated that I have in production

  • @amphetaminocid
    @amphetaminocid Před rokem +1

    Please keep up. This video is awesome.

  • @ImranKhansilvake
    @ImranKhansilvake Před rokem +1

    very nice. Thanks for the video

  • @briandevs
    @briandevs Před 2 lety +1

    Thanks best content of react and typescript!

  • @sumanmarahatha4274
    @sumanmarahatha4274 Před 2 lety +2

    Needed full series on react testing library with jest

  • @aghileslounis
    @aghileslounis Před 2 lety +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 ?

  • @victorbadaro
    @victorbadaro Před 2 lety +1

    wow man... what a video!

  • @SajidAliSoftwareEngineer
    @SajidAliSoftwareEngineer Před 2 lety +1

    Indeed a great video.

  • @igotbit9454
    @igotbit9454 Před 2 lety +1

    perfect i needed this.
    thx

  • @matthewrideout426
    @matthewrideout426 Před rokem

    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

  • @andyazma4198
    @andyazma4198 Před rokem +1

    Thanks a lot, it's amazing video :)

  • @herbertpimentel
    @herbertpimentel Před 2 lety +1

    OMG 😍 thank you... Again.

  • @Berkeli
    @Berkeli Před 2 lety +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

  • @FragmentFrontDeveloper

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

  • @chaboxx159c
    @chaboxx159c Před rokem +2

    thanks man ur really awesome

  • @ionut.vidrighin
    @ionut.vidrighin Před rokem +1

    This tutorial is so damn good and I can admit that you're an incredible teacher on React; never found someone else here on CZcams providing better explanations and better experience overall. Super !!

  • @igormundim
    @igormundim Před 10 měsíci

    The best. Obrigado!

  • @mehmetsayn573
    @mehmetsayn573 Před 2 lety +1

    Everything in nutshell. Thanks

  • @eisanodehi
    @eisanodehi Před 2 lety +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.

  • @djaniivanov4117
    @djaniivanov4117 Před 2 lety

    good video! i'd like to see a full-stack build by you. App with front-end typescript with react,state management and backend part with express and mongo for example + tests.That's is a good idea for a series of videos i think.Greetings!

  • @soulos45
    @soulos45 Před rokem +1

    Thanks!

  • @user-gs2zp3dm1v
    @user-gs2zp3dm1v Před rokem +1

    thanks a ton

  • @marvinotieno2194
    @marvinotieno2194 Před 4 měsíci

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

  • @27sosite73
    @27sosite73 Před 5 měsíci +1

    thank you

  • @keiji0075
    @keiji0075 Před 2 lety +1

    more than best

  • @mridulmishra8166
    @mridulmishra8166 Před 2 lety +1

    Wow.. just wowww

  • @anujupadhyay10
    @anujupadhyay10 Před rokem +1

    10/10 😉

  • @chauhan035
    @chauhan035 Před 2 lety +1

    Awesome

  • @arupkumargupta6128
    @arupkumargupta6128 Před rokem

    Its a great tutorial. Thanks. One question on testing async custom hooks
    How do you test the cleanup of the use effect?

  • @ponderatulify
    @ponderatulify Před 2 lety +1

    You just love pronouncing zuStand :))

  • @brentmarquez4157
    @brentmarquez4157 Před 2 lety

    This was great - any chance of doing a TDD demonstration with React? Or maybe a demonstration of testing Sagas?

  • @thatWebGuySolutions
    @thatWebGuySolutions Před 11 měsíci

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

  • @amitsinghrawat4760
    @amitsinghrawat4760 Před 2 lety +2

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

  • @georgy2763
    @georgy2763 Před rokem

    Do you use userEvent over fireEvent in some scenarios? I heard that it’s better, but I am not sure. Are you planning to do more videos on testing? Your videos helping me to go through my internship)

  • @amajuify
    @amajuify Před rokem

    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?

  • @ngneerin
    @ngneerin Před 2 lety +4

    We need NodeJS+Typescript Testing

  • @MrKeepItTrill
    @MrKeepItTrill Před 2 lety +1

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

    • @jherr
      @jherr  Před 2 lety

      I don't think so.

  • @miguelship3
    @miguelship3 Před rokem

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

  • @gmil12345
    @gmil12345 Před 2 lety

    Hi, did you not have to set up a handlers file for the MSW stuff? can't seem to get mine to work

  • @vittoriomorellini1939
    @vittoriomorellini1939 Před 11 měsíci

    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

  • @tomascarignano5002
    @tomascarignano5002 Před 2 lety +1

    Yesssss

  • @wesleyhandy7528
    @wesleyhandy7528 Před 2 lety +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  Před 2 lety

      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.

  • @dailymeow3283
    @dailymeow3283 Před 2 lety +2

    Lol i like the thumbnail 🤭🤭

  • @SyedZainUlHasan
    @SyedZainUlHasan Před rokem +1

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

    • @jherr
      @jherr  Před rokem

      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.

  • @devsami
    @devsami Před 7 měsíci

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

  • @ahmedsoran4710
    @ahmedsoran4710 Před rokem

    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?!

  • @GoodHomeVideos
    @GoodHomeVideos Před 11 měsíci

    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.

  • @decentrob8126
    @decentrob8126 Před 2 lety

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

  • @mani8586
    @mani8586 Před 2 lety +2

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

  • @someonewhowantedtobeahero3206

    Loved this one. Does anyone know what theme and font he's using? Looks neat.

    • @jherr
      @jherr  Před 2 lety +2

      Night Wolf [dark] and MonoLisa.

    • @someonewhowantedtobeahero3206
      @someonewhowantedtobeahero3206 Před 2 lety

      @@jherr Thanks a lot! MonoLisa seems to be a paid font so I settled for Cascadia Code, and my editor looks great after a few background color tweaks.

  • @MrRobeezy29
    @MrRobeezy29 Před 2 lety +1

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

    • @jherr
      @jherr  Před 2 lety

      GitHub Copilot,