React Testing Library Tutorial #12 - Finding Async Elements with FindBy

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ต.ค. 2024

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

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

    This is a gem tutorial since so many React courses out there but not so many React Testing Library courses. This is def what I am looking for. Thank you!

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

    Really loved this series ! I have started to love writing tests. It was earlier a nightmare. Thank you so much 😊

  • @aveek.roy.
    @aveek.roy. 2 ปีที่แล้ว +5

    findTestById is failing for me - any suggestions how to resolve it?
    getting the below error:
    Unable to find an element by: [data-testid="follower-item-0"]

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

    findBy methods are not working as shown here. In the FollowersList.js file the following error is being listed:
    _TypeError: Cannot destructure property 'data' of '(intermediate value)' as it is undefined._

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

      Solution: Delete the [src/_ _ mocks _ _] folder and rerun npm run test.

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

      @@debarghyachakraborty Why does this occur?

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

      Thank you! Have been trying to figure this out for a while now.

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

      @@debarghyachakraborty Doesn't work

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

      @@debarghyachakraborty WOW! you are right. Why was this the case? Any idea

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

    Gave a boost to face the interview questions on react unit testing

  • @dawid_dahl
    @dawid_dahl 2 หลายเดือนก่อน

    Do you recommend to query by test-id rather than by say the className? Maybe doing that is less brittle since developers maybe are more likely to change a className than a test-id?

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

    There is a problem with the recent axios v1.2. It will give import error. Add the below line at the end of package.json
    "jest": {
    "transformIgnorePatterns": ["node_modules/(?!axios)/"]
    }
    restart the test and it will work. This is a temporary solution until axios fixes it

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

    Hey Bro I love the way you are Explaining the test Thank you so much for the course.
    please can we add a video for the Redux Testing........................

  • @deynerfranciscolezcano5586
    @deynerfranciscolezcano5586 11 หลายเดือนก่อน

    I am not sure about the use of getByTestId. Is it part of good practices to actually use those "data-testId" in our code?

  • @Poopuupoo
    @Poopuupoo 7 หลายเดือนก่อน

    Hey @6:30 the code 'follower-item-${index}' how come your ${index) is unaffected by the quotation?

    • @Poopuupoo
      @Poopuupoo 7 หลายเดือนก่อน

      mine is, and I think that is causing my test to fail.

    • @Poopuupoo
      @Poopuupoo 7 หลายเดือนก่อน

      Okay nevermind -solved. its not a quotation, its a backtick.

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

    can we create only one one __test__ folder for all components which are we going to test?

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

    best testing course thanks 🚀

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

      No problem, thanks for the support Mehmet :)

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

    Hey bro, I really like your course and I want to make a similar course of this in spanish, do you have any problem if I use some of your examples? obviusly I will mention you

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

      Go ahead.

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

      @@thiagoleite3255 lmao like you own this course

  • @1111ah
    @1111ah ปีที่แล้ว

    Love the course... thanks!

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

    Nice tutorial! but I do want to point out, that you shouldn't use index as a key, since the index will change if you add/remove an item, and cause inefficiencies in the re-render. You should instead use the id, or some other unique identifier

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

      He already said this wasn't the best practice.

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

    Awesome tutorial… thank you

  • @Human_Evolution-
    @Human_Evolution- 2 ปีที่แล้ว

    I could not re-create these results with my app. 2 hours of trying...... Someone help me. 5 days of studying tests and I have 0 meaningful tests written..........

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

    you are a life saver. thanks a lot for this video

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

    If your tests are failing for this, remove __mocks__ in src, problem will be fixed.

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

    it doent work i always error

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

    U r the best

  • @OmarBalah-h8s
    @OmarBalah-h8s 3 ปีที่แล้ว

    What is a program do you record your screen

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

    Please upload new django course

  • @dangerzone-136
    @dangerzone-136 3 ปีที่แล้ว

    Really awesome tutorial. Could you please create a shopping website with all features{filter, color, variants etc} using React hooks and api?

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

      Something else?

    • @dangerzone-136
      @dangerzone-136 3 ปีที่แล้ว

      @@thiagoleite3255 That's Enough. Thanks for your valuable time. Hoping to see new video from you soon.

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

    To solve the error: "Unable to find an element by ..."
    The code below will fix it..
    .
    .
    .
    import { render, screen, waitFor } from '@testing-library/react';
    const followerDivElement = await waitFor(
    () => screen.findByTestId('follower-item-0'),
    { timeout: 5000 }
    );
    .
    .
    .
    It seems the amount of time the API returns our data is more than 1 second (default timeout duration).
    We can use waitFor method to configure the timeout duration.
    Then just add key={index} to element on FollowersList.js to fix the next error..

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

      Still doesn't work

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

      @@PixelTB its cause the server isnt always returning data 529 error. I its work if u run it enough times..

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

      @UCBMw2sInVKJOsNRsFxPpr7g I tried using screen.findByTestId() and sometimes it did work, and sometimes it didn't, it's probably because it takes a little bit of time to fetch the data.

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

    lol its funny, that you used in every vid async without awaiting anything but in this vid you removed it, to show how to add async.lol

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

    thrown: "Exceeded timeout of 5000 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test." i am facing this issue can some one help?

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

    Everything you're doing seems to use getByTestId ... this is supposed to be the last resort and pretty much not suggested ... are you sure you know what you're doing? I miss Net Ninja ... the real one. You are ruining his good name!!!