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

Поділитися
Вставка
  • Опубліковано 5 сер 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
  • Наука та технологія

КОМЕНТАРІ • 161

  • @adamwoolf9993
    @adamwoolf9993 2 роки тому +2

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

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

  • @curiousprogrammer90
    @curiousprogrammer90 2 роки тому +11

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

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

  • @hameedhameed5542
    @hameedhameed5542 2 роки тому +2

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

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

  • @idilenebrito6570
    @idilenebrito6570 Рік тому +1

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

  • @JC-yy5nf
    @JC-yy5nf Рік тому

    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!

  • @avinashvivek
    @avinashvivek Рік тому

    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 Рік тому +2

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

  • @EduardoYudjiNagashimaMiyata
    @EduardoYudjiNagashimaMiyata 8 місяців тому +1

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

  • @manantank
    @manantank 2 роки тому +2

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

  • @iqwebserve3973
    @iqwebserve3973 Рік тому +1

    Excellent for newbies and as a refresher! Thanks!

  • @herubond3610
    @herubond3610 2 роки тому +6

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

    • @jherr
      @jherr  2 роки тому

      Thanks!

  • @nattysweg343
    @nattysweg343 Рік тому +1

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

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

  • @HotRatsAndTheStooges
    @HotRatsAndTheStooges 2 роки тому +1

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

  • @andriimuntian3632
    @andriimuntian3632 2 роки тому +1

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

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

  • @tarunsukhu2614
    @tarunsukhu2614 2 роки тому +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  2 роки тому +1

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

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

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

  • @joraanbe
    @joraanbe 2 роки тому +1

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

  • @khudadadrasikh
    @khudadadrasikh 2 роки тому +1

    I found it very helpful. Thank you Jack Herrington

  • @yasin_osman
    @yasin_osman 2 роки тому +1

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

  • @ralphlargo9728
    @ralphlargo9728 2 роки тому +1

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

  • @aaronmcadam
    @aaronmcadam 2 роки тому +1

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

  • @mahu_4312
    @mahu_4312 2 роки тому +1

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

    • @jherr
      @jherr  2 роки тому

      You are very welcome. Happy to have your views!

  • @bafian
    @bafian 2 роки тому +1

    great content as always, loved zustand.

  • @shivashankar6043
    @shivashankar6043 2 роки тому +3

    Jack never failed to give awesome contents 👏

  • @AlinaTudose
    @AlinaTudose 8 місяців тому +1

    That was so clean and clear 😊

  • @worldhello4012
    @worldhello4012 Рік тому

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

  • @holdmybeaver
    @holdmybeaver 2 роки тому +1

    thank you, Jack, great content as always!

  • @sanazseifi5105
    @sanazseifi5105 Рік тому +1

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

  • @nimapourmohammadi4854
    @nimapourmohammadi4854 Рік тому +1

    Really Helpful and clean solutions. Thanks

  • @alexanderleonardo5649
    @alexanderleonardo5649 2 роки тому

    fast and easy to understand. thx

  • @mycovearomany455
    @mycovearomany455 Рік тому +2

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

  • @pfcosta84
    @pfcosta84 2 роки тому +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  2 роки тому +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

  • @tsooooooo
    @tsooooooo 2 роки тому +1

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

  • @boot-strapper
    @boot-strapper 2 роки тому +2

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

    • @jherr
      @jherr  2 роки тому +1

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

  • @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! =)

  • @Satender-cd7zu
    @Satender-cd7zu 4 місяці тому +1

    Thanks, you just solved my 3 hour work!

  • @antonioteixeira1779
    @antonioteixeira1779 5 місяців тому +1

    Awesome, thank you from Brazil!

  • @donotthink
    @donotthink 2 роки тому +1

    This here is quality content! Thank you!

  • @murtazasalim7572
    @murtazasalim7572 2 роки тому +1

    awesome explanation and methodology
    .

  • @fotios4902
    @fotios4902 2 роки тому +1

    Thanks for the awesome tutorial!

  • @ionut.vidrighin
    @ionut.vidrighin Рік тому +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 UA-cam providing better explanations and better experience overall. Super !!

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

  • @vittoriomorellini1939
    @vittoriomorellini1939 Рік тому

    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

  • @parushanaidoo9183
    @parushanaidoo9183 Рік тому +1

    Thank you for this tutortial. It really helps

  • @Errorisedqt
    @Errorisedqt Рік тому

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

  • @ImranKhansilvake
    @ImranKhansilvake Рік тому +1

    very nice. Thanks for the video

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

  • @amphetaminocid
    @amphetaminocid Рік тому +1

    Please keep up. This video is awesome.

  • @briandevs
    @briandevs 2 роки тому +1

    Thanks best content of react and typescript!

  • @SajidAliSoftwareEngineer
    @SajidAliSoftwareEngineer 2 роки тому +1

    Indeed a great video.

  • @victorbadaro
    @victorbadaro 2 роки тому +1

    wow man... what a video!

  • @sumanmarahatha4274
    @sumanmarahatha4274 2 роки тому +2

    Needed full series on react testing library with jest

  • @igotbit9454
    @igotbit9454 2 роки тому +1

    perfect i needed this.
    thx

  • @igormundim
    @igormundim 11 місяців тому

    The best. Obrigado!

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

  • @andyazma4198
    @andyazma4198 Рік тому +1

    Thanks a lot, it's amazing video :)

  • @FragmentFrontDeveloper
    @FragmentFrontDeveloper Рік тому

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

  • @herbertpimentel
    @herbertpimentel 2 роки тому +1

    OMG 😍 thank you... Again.

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

  • @chaboxx159c
    @chaboxx159c Рік тому +2

    thanks man ur really awesome

  • @mehmetsayn573
    @mehmetsayn573 2 роки тому +1

    Everything in nutshell. Thanks

  • @soulos45
    @soulos45 Рік тому +1

    Thanks!

  • @marvinotieno2194
    @marvinotieno2194 4 місяці тому

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

  • @user-gs2zp3dm1v
    @user-gs2zp3dm1v Рік тому +1

    thanks a ton

  • @27sosite73
    @27sosite73 6 місяців тому +1

    thank you

  • @djaniivanov4117
    @djaniivanov4117 2 роки тому

    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!

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

  • @keiji0075
    @keiji0075 2 роки тому +1

    more than best

  • @chauhan035
    @chauhan035 2 роки тому +1

    Awesome

  • @mridulmishra8166
    @mridulmishra8166 2 роки тому +1

    Wow.. just wowww

  • @anujupadhyay10
    @anujupadhyay10 Рік тому +1

    10/10 😉

  • @arupkumargupta6128
    @arupkumargupta6128 Рік тому

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

  • @ponderatulify
    @ponderatulify 2 роки тому +1

    You just love pronouncing zuStand :))

  • @tomascarignano5002
    @tomascarignano5002 2 роки тому +1

    Yesssss

  • @ngneerin
    @ngneerin 2 роки тому +4

    We need NodeJS+Typescript Testing

  • @brentmarquez4157
    @brentmarquez4157 2 роки тому

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

  • @amitsinghrawat4760
    @amitsinghrawat4760 2 роки тому +2

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

  • @thatWebGuySolutions
    @thatWebGuySolutions 11 місяців тому

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

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

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

  • @dailymeow3283
    @dailymeow3283 2 роки тому +2

    Lol i like the thumbnail 🤭🤭

  • @georgy2763
    @georgy2763 2 роки тому

    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)

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

  • @SyedZainUlHasan
    @SyedZainUlHasan Рік тому +1

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

    • @jherr
      @jherr  Рік тому

      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.

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

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

  • @gmil12345
    @gmil12345 2 роки тому

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

  • @miguelship3
    @miguelship3 Рік тому

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

  • @wesleyhandy7528
    @wesleyhandy7528 2 роки тому +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  2 роки тому

      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.

  • @someonewhowantedtobeahero3206
    @someonewhowantedtobeahero3206 2 роки тому +1

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

    • @jherr
      @jherr  2 роки тому +2

      Night Wolf [dark] and MonoLisa.

    • @someonewhowantedtobeahero3206
      @someonewhowantedtobeahero3206 2 роки тому

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

  • @techworld3043
    @techworld3043 2 роки тому +1

    nice thumbnail. jacky

  • @brunofilgueiras3518
    @brunofilgueiras3518 Рік тому

    hi Jack, first of all I looooove all your videos, just a simple question, was the isMounted variable really important for the tests on the APIComponent testing, removing it didn't interfere on the tests here...

    • @jherr
      @jherr  Рік тому

      Can you give me a time reference? It's very possible it's not required.

    • @brunofilgueiras3518
      @brunofilgueiras3518 Рік тому

      oh sorry@@jherr, I came back again to review your video and just saw your comment 😅... it would be around 14:50, and you said that was a way to safeguard or prevent that request from being called after the component is unmounted, I was trying to imagine that scenario actually 🤔

    • @brunofilgueiras3518
      @brunofilgueiras3518 Рік тому

      @@jherr will take this opportunity to ask you if you can someday make a video about component decoupling strategies with some examples, would love to know how you work around this issue.

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

  • @decentrob8126
    @decentrob8126 2 роки тому

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