How to Test In React - React Testing Library + Jest Tutorial

Sdílet
Vložit
  • čas přidán 12. 09. 2024
  • In this video I will teach you guys how test in react using the react testing library and jest. Testing is very important when building an application!
    -
    ❤️ Want to Support the Channel?:
    / @pedrotechnologies
    🚀 Learn ReactJS By Building 6 Projects: codedamn.com/l...
    -
    Social
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Website: machadopedro.com
    Linkedin: / machadop1407
    Instagram: / _pedro.machado_
    Github: github.com/mac...
    Email: machadop1407@gmail.com
    Tags:
    - ReactJS Tutorial
    - ReactJS and MySQL
    - NodeJS Tutorial
    - API Tutorial
    #PedroTech #react #reactjs #reacttestinglibrary

Komentáře • 42

  • @PedroTechnologies
    @PedroTechnologies  Před 3 lety +12

    Had to repost the video cause I realized the audio was extremely low! Hope you all enjoy it :)

    • @PedroTechnologies
      @PedroTechnologies  Před 3 lety +1

      Another thing, I like using data-testid but sometimes it is totally recommended to use other identifiers. Test id is a very specific identifier, which differs from others like title/id/classname. Some people recommend using data-testid only for the last resort, however some people also argue in favour of using it most times. It depends on what you chose :)

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

    Hello Pedro ! thank you so much for the video

  • @tomasburian6550
    @tomasburian6550 Před 2 lety

    Every job I had had me do tests. This is extremely important to understand. Also having graphics coverage reports helps a lot, the testing library can generate an html which shows how much you've covered.

  • @ericdecolsales3066
    @ericdecolsales3066 Před rokem

    AEE PORRAAA EU vim do React native de empresa onde a gente testava as coisas direito, fui achar seu video na 4 pagina e FINALMENTE UM TESTE QUE PRESTA, a maioria era porcaria pegando por texto ou getElement, pelo amor de deus, ALELUIA, MUITO OBRIGADO
    VAI BRASILLLL

  • @nasermohdbaig7232
    @nasermohdbaig7232 Před 2 lety

    Thank you Pedro, this is really helpful. I have always been afraid of writing tests because it was like a blackbox to me but the way you explained has unwrapped many confusing concepts. Cheers :)

  • @kranthikumar5215
    @kranthikumar5215 Před rokem +1

    Love u pedro ❤

  • @thatigangadhar3627
    @thatigangadhar3627 Před 2 lety

    Thanks a lot pedro, i am searching for this type of clear explanation and do more videos ...

  • @didkei
    @didkei Před 2 lety

    I love your videos, you explain everything so well and make it seem like a child's play

  • @youssefel-h5074
    @youssefel-h5074 Před rokem

    Thanks, that was helpful.

  • @zerdnelemo
    @zerdnelemo Před 3 lety

    Excellent video Pedro. Concepts were very clearly addressed.
    Thanks for sharing this!

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

    Hi. Loving the video. At 16:10 you said you'd put a link in the description for the documentation for { render }. Can you post that please?
    Thanx

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

    Hi I have seen really awesome content on your channel, can you do a video, how to use react project **MUI with styled-components library both together**, including how to set theme/how to style components and advanced concept (how to style set up this for enterprise app,etc), what are the best way use both library togehter,bcz ,there are no proper reference out there for that use case.hope you will create a awesome, project on this content.

  • @okidokiyowyow356
    @okidokiyowyow356 Před 3 lety

    Fucking thanks man! I hope you do more test but on a bigger project? I've been following you for a while and I learned a lot from you.

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

    Thanks Pedro , just to ask . Would the implementation differ a lot when typescript is used ??

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

    super helpful!

  • @majuladarks.8708
    @majuladarks.8708 Před 2 lety

    Boa Pedroca! Brabo demais.

  • @blue_berry_pie64
    @blue_berry_pie64 Před rokem

    Thank youuuuuu

  • @romanmelon5845
    @romanmelon5845 Před 2 lety

    Thank you!

  • @oshinbatra4319
    @oshinbatra4319 Před rokem

    my tests failed. Error shows :
    TestingLibraryElementError: Unable to find an element by: [data-testid="button"]
    what could be the possible error i made?

  • @moylababa8196
    @moylababa8196 Před 3 lety

    Will we test after the whole Reactjs application is finished? or do it after a component is finished?

  • @Lohitpant
    @Lohitpant Před 2 lety

    Great

  • @mayurghuge8846
    @mayurghuge8846 Před 2 lety

    Thanks.

  • @achrefsmida7813
    @achrefsmida7813 Před 2 lety

    hello i always find this problem with redux Request User › rendered input
    could not find react-redux context value; please ensure the component is wrapped in a
    any solution please

  • @daniel4661
    @daniel4661 Před 2 lety

    dude, where's the specific git repository for this project?...thank you in advance...

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

    I'm facing a problem with `act`. Can anyone help? When I use `getByTestId` within `act` it says TestingLibraryElementError: Unable to find an element by: [data-testid="searchBar"] . I entered the testid string correctly. If I remove the act function and place `getByTestId` outside of it, it is working. Don't understand why.

    • @chaitu6081
      @chaitu6081 Před 2 lety

      @@faisalsayyed8877 not yet

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

      The problem is that it's looking up a component that isn't rendered yet. Putting the whole testing function into async doesn't work in this case, just put async onto the function which contains the fireEvent method and let it show the warning. The test will pass anyway.

  • @danielmagar5196
    @danielmagar5196 Před rokem

    How to mock api

  • @Shin-jj3qt
    @Shin-jj3qt Před 3 lety +1

    Do you do TDD in your current job?

  • @atanujana8119
    @atanujana8119 Před 3 lety +1

    pls create a video on 2 file upload using two different from tag using react js and cloudinary 🙏🏻🙏🏻🙏🏻🙏🏻

  • @ainneo
    @ainneo Před 2 lety

    is there code somewhere posted?

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

    This literally didnt work for me for some reason, digging into the docs they literally say " it is recommended to use GetByTestId only after the other queries don't work for your use case. Using data-testid attributes do not resemble how your software is used and should be avoided if possible."
    Video is a bit below what I usually see from this channel tbh

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

      I'm sorry to hear that! I am planning on more testing videos soon. My plans are to do one updated video on React testing and one on backend testing. I get what you mean, and you are right about the GetByTestid.

    • @ssj1260
      @ssj1260 Před 2 lety

      @@PedroTechnologies Thanks man, if im stuck on something and I see a video by you on the topic, I go for it. Don't want others to see bad practices and avoid your channel as being unreliable. that was just my constructive criticism.

    • @mana748
      @mana748 Před 2 lety

      Hi @@ssj1260, I'd been through it as well and trying to figure out what was wrong before going for a real solution.
      You can easily solve this problem by using 'screen' from the same library. Once your code's been repaired, it should look something like this:
      import { render, screen, fireEvent } from '@testing-library/react'
      const input = screen.getByTestId('searchbar')
      Pedro has probably mentioned it in his last video about the topic though.

  • @indrasen9617
    @indrasen9617 Před 2 lety

    Please share the documentation link at 16:09

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

    I hated testing till now

  • @DuyTran-ss4lu
    @DuyTran-ss4lu Před 3 lety

    Great