React TDD in 30 Minute - Test Driven Development with Jest and Enzyme

Поділитися
Вставка
  • Опубліковано 8 лют 2025
  • Test-Driven Development ( #TDD ) in #reactjs with #jest and #enzyme testing libraries
    In just 30 minutes, we will know the benefits of TDD and how to follow Test Driven Development in Reactjs by using Jest and Enzymes.
    Useful Links:
    React: reactjs.org/do...
    Jest: jestjs.io/
    Enzyme: airbnb.io/enzyme/
    Github Source Code:
    github.com/bit...
    ======================= Ad Free Tutorials ======================
    Check bitfumes.com For ads-free and more advanced courses (use Coupon code WELCOME60 to get 60% discount)
    ==================FOLLOW ME ==================
    Subscribe for New Releases!
    Twitter - / bitfumes
    Facebook - / bitfumes
    Instagram - / bitfumes
    (ask me questions!)
    -- QUESTIONS? --
    Leave a comment below and I or someone else can help you.
    For quick questions you may also want to ask me on Twitter, I respond almost immediately.
    Email me support@bitfumes.com
    Thanks for all your support!

КОМЕНТАРІ • 192

  • @naderazimi6786
    @naderazimi6786 4 роки тому +25

    I started today to learn unit testing. I tried different youtube videos and I have to say your 30 minutes course on unit testing was by far the best. I understood a great deal about unit testing. Great explanation and method of teaching. I tried it with react 17 which caused problem but I managed to figure it out and it worked.

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

    This is a great explanation! This demo can make anyone understand...what is jest and enzyme exactly and how we can use it together for writing unit test cases for react. Thank you!

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

      Glad it was helpful!

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

    Seriously! You are done with a great concept. As much as simple you made. Thank you!

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

    Short and concise. Thank you for your work ^^

  • @natow.b
    @natow.b 4 роки тому +2

    had to work on TDD for a new client project, great explanation helped me dip my toes

  • @badvibezforever7
    @badvibezforever7 4 роки тому +8

    Great explanation! I can finally understand how to test react code. Thank you!

  • @Fooljuice
    @Fooljuice 3 роки тому

    This is the best tutorial. Thanks Bitfumes! You rock.

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

    Loved this. Thanks a ton for the video! I never wrote the automated Test cases for my React Project though I have been working on it for the past 9 months.
    This video is on point and explains almost everything to start with. Thanks a ton again!

    • @Bitfumes
      @Bitfumes  3 роки тому +1

      Glad it was helpful!

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

    Best tutorial to get started with React TDD. Give this a go :)

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

      Awesome, glad you liked it
      Please hit like and share with your friends

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

      @@Bitfumes Shared already : ). But Enzyme is dead right? What should we go for then?

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

    You helped me a lot.
    I am now clear about test driven development

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

    Love your videos. Thanks so much! Your series on Javascript prototypes and constructors helped me so much when I was a newbie in bootcamp. Thanks again and please keep making this content. Thanks 🙂

  • @PierreOlivierTran
    @PierreOlivierTran 3 роки тому +1

    "I am so excited that I want to create button that decrements counter". You just summed up the life of a developer.

    • @Bitfumes
      @Bitfumes  3 роки тому

      that's so amazing bro, please share your progress on twitter and just tag me there @sarthaksavvy

  • @Nikki-fs2kt
    @Nikki-fs2kt 4 роки тому +7

    this tutorial is amazing!! You made it very easy to understand!! Thank you!

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

    Loved your work. You made it very easy and clear.

  • @prisinha
    @prisinha 3 роки тому +1

    Sarthak , can I humbly request a video on yourself as how you learnt TDD, about your employment, your family , your work schedule and your projects.

  • @agustinlavalla4928
    @agustinlavalla4928 4 роки тому +3

    Great lesson to start with testing in react. Thanks so much, I appreciate your effort.

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

    Thank you! It's an awesome video! easy to understand! you know beginners' thought. At the end, I wonder why doesn't the test work after creating Counter component, and you explained it! Ah~~ Thank you so much!

  • @GuilleAcosta124
    @GuilleAcosta124 3 роки тому +5

    we need more TDD React tutorials!

  • @QiroLab
    @QiroLab 5 років тому +1

    You explained it in very easy way. 👏 👏 amazing.

  • @DB-jh8cg
    @DB-jh8cg 3 роки тому

    really awesome tutorial to start reactjs testing with enzyme and jest!!!

  • @abdous-i8s
    @abdous-i8s 4 роки тому +17

    "I'm so excited to create another test" xD Yeye sure. Excited to create a test:D

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

      Creating a test might not be exciting, but seeing a test first fail and then succed is very satisfying

  • @adeniyitaofik3832
    @adeniyitaofik3832 4 роки тому +1

    This is awesome this was awesome and i am greatful for this you deserve a lot of accolade

  • @luisnomad
    @luisnomad 5 років тому +2

    Great video, thank you so much for taking the time to do it.

    • @Bitfumes
      @Bitfumes  5 років тому

      Thanks for your love and support, keep learning. Follow bitfumes on twitter.com/bitfumes or facebook.com/Bitfumes to get the latest updates.
      bitfumes.com

  • @VVe11erMichae1
    @VVe11erMichae1 4 роки тому +1

    Thanks for the video, Very clear and easy to understand!

  • @luanfelipecosta
    @luanfelipecosta 4 роки тому +1

    why I never thought about moving the sidebar to right? amazing! haha love it. thanks! amazing video

    • @Bitfumes
      @Bitfumes  4 роки тому +1

      Hahahaha, just for fun

  • @jerrydavidson4226
    @jerrydavidson4226 4 роки тому +1

    This in amazing tutorial on how to approach TDD. Thanks

  • @royaloppression
    @royaloppression 4 роки тому +1

    Great video, very easy to understand and follow!

  • @kimliverpool1
    @kimliverpool1 5 років тому +2

    Thank you. I learned so much. Always be happy.

  • @ankitmehrotra8519
    @ankitmehrotra8519 4 роки тому

    Great Video Sarthak..Thanks a lot..Keep making such awesome videos..

  • @dzengiztafa510
    @dzengiztafa510 4 роки тому +1

    This is really a well brought tutorial. Nice work!

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

    Great video you explain it so well, here is my solution.
    test('render 0 when decrement button clicked on counter value of 0', ()=>{
    wrapper.find('#decrement-btn').simulate('click');
    expect(wrapper.find('#counter-value').text()).toBe("0")
    })
    counter > 0 ? setCounter(counter - 1): null} id="decrement-btn">Decrement

  • @gomesdev
    @gomesdev 3 роки тому

    Thanks for the tutorial, excellent!

  • @ammadunaani
    @ammadunaani 4 роки тому

    Thank you for the wonderful explanation and nice way to teach TDD👍😀

  • @roberto9369
    @roberto9369 3 роки тому +1

    nice work man. very well explained

  • @sirajAlam049
    @sirajAlam049 4 роки тому +12

    In case anybody looking for the answer of the homework.
    test('do not decrement below zero', () => {
    wrapper.find('#dcr-btn').simulate('click');
    expect(wrapper.find('#counter-value').text()).toBe("0");
    })

    • @sreeharithiruveedhi3104
      @sreeharithiruveedhi3104 3 роки тому

      What is the logic in app.js

    • @santhoshsuriya8640
      @santhoshsuriya8640 3 роки тому

      @@sreeharithiruveedhi3104 counter > 0 && setCounter(counter - 1)}>
      Decrement

    • @bhojakrahul5880
      @bhojakrahul5880 3 роки тому

      @@santhoshsuriya8640 brother i do same but i get error for button not allow to be 10
      {counter < 10 && setCounter(counter + 1)
      }}
      >
      Increment
      .......
      test('Do not Increment below 10', () => {
      wrapper.find("#increment-btn").simulate('click');
      expect(wrapper.find("#counter-value").text()).toBe("10");
      })
      any idea

    • @monikan9854
      @monikan9854 3 роки тому

      @@bhojakrahul5880 Here u are trying to do increment only when the counter is less than 10 right 'Do not Increment above 10' right

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

    thank you Bro ... this is a very good tutorial on TDD

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

      Glad it was helpful!

  • @abdous-i8s
    @abdous-i8s 4 роки тому +3

    Dude Amazing Video, thank you!

    • @Bitfumes
      @Bitfumes  4 роки тому

      Abdou Seck thanks for your love and support keep learning

  • @valikonen
    @valikonen 3 роки тому +1

    I really enjoy this tutorial. It is so easily compared with Angular/Jasmine. Thank you for your clean work!

  • @MrPlaiedes
    @MrPlaiedes 4 роки тому +1

    Love your video. Great teacher!

  • @JoAndStepi
    @JoAndStepi 4 роки тому

    Simple and easy explanation!

  • @chiho8119
    @chiho8119 3 роки тому

    Damn I was not really a fan of testing stuff, but you inspired me to have fun with unit testing...

  • @gunishmatta
    @gunishmatta 4 роки тому

    Thanks a lot bro best video for beginners.

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

    here is my homework, just added a couple more lines to the already existent test:
    test("render the click event, decrement and increment value", () => {
    wrapper.find("#increment-btn").simulate("click");
    expect(wrapper.find("#counter-value").text()).toBe("1");
    wrapper.find("#decrement-btn").simulate("click");
    expect(wrapper.find("#counter-value").text()).toBe("0");
    added:
    ```wrapper.find("#decrement-btn").simulate("click");
    expect(wrapper.find("#counter-value").text()).toBe("0");```
    });
    also, thanks, very valuable 30 minutes!

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

    Thank you for the video.
    This was my test:
    test("renders the 0 when decrement button is Clicked, Counter should Not go below that", () => {
    wrapper.find("#decrementBtn").simulate('click');
    expect(wrapper.find("#counterValue").text()).not.toContain("-");
    });
    counter > 0 && setCounter(counter - 1)}
    id="decrementBtn"
    >
    decrement

  • @natnaelsisay1424
    @natnaelsisay1424 4 роки тому

    It was Informative and nice video. Thank you

  • @mzwandilendimba2024
    @mzwandilendimba2024 5 років тому

    Excellent video sir, enjoyed it I am going to start implementing everything I learned here

  • @saadchouar
    @saadchouar 4 роки тому

    Thanks for the content ! Simple Fast and Effective !

  • @RTXonerix
    @RTXonerix 3 роки тому

    This is how I did the homework test, and implemented simple logic fot the counter to NOT go negative:
    The test:
    wrapper.find("#increment-btn").simulate("click");
    expect(wrapper.find("#counter-value").text()).toBe("1");
    wrapper.find("#decrement-btn").simulate("click");
    wrapper.find("#decrement-btn").simulate("click");
    expect(wrapper.find("#counter-value").text()).toBe("0");
    The simple logic inside a button:
    onClick={() => (counter

  • @brucelee7782
    @brucelee7782 3 роки тому +3

    I dont understand at 3:58 why did he use the command under "without create react app" when he just used npx create-react-app a few seconds earlier. I couldnt run my test following this at all and only resolved it after using the command under setup WITH react app

  • @sajjadhoviegar5950
    @sajjadhoviegar5950 2 місяці тому

    Thanks for the great tutorial, but I noticed one problem when I saw in 21:16 that you changed the previous value of a state using the current state, which is bad. You should change the state using a callback function passed to the setCounter like so: setCounter((prevState) => {prevState + 1} ).

  • @bervinmance1706
    @bervinmance1706 3 роки тому

    Good and simple explanation thanks

    • @Bitfumes
      @Bitfumes  3 роки тому

      Thanks for your love and support, keep learning. Subscribe to bitfumes newsletters
      bitfumes.com/newsletters

  • @Robloxgaming-x6h
    @Robloxgaming-x6h 3 роки тому

    thanx man, very helpful

  • @lefeezy
    @lefeezy 4 роки тому

    Very helpful. Thanks!

  • @sai_yerni_akhil
    @sai_yerni_akhil 4 роки тому +31

    jest comes default wit create-react-app, so no need to install them separately

    • @JamEs-ej1vy
      @JamEs-ej1vy 4 роки тому +3

      yeah I followed the tutorial verbatim and it gave me errors running the test because of the installation of babel testing. I tried again following the documentation and it worked fine

    • @fit_guy
      @fit_guy 4 роки тому

      ya bro

  • @ciprianlupsa557
    @ciprianlupsa557 4 роки тому +1

    very good tutorial. well done

    • @Bitfumes
      @Bitfumes  4 роки тому

      Thank you! Cheers!

  • @ManishKumar-mi7ko
    @ManishKumar-mi7ko 3 роки тому

    awesome with simplicity👏

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

    Any suggestions on how test files should be organized in a react app project? Should all tests be in the same folder as the component, or should all tests just be together in a different file? Whats the best practice?

  • @ritheeshthomas2732
    @ritheeshthomas2732 3 роки тому

    great explanation

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

    Amazing tutorial....!!!!

  • @jasbirsingh-mv5vh
    @jasbirsingh-mv5vh 3 роки тому +2

    Why did we installed jest thing, its working fine here without installing jest and its dependencies, i only installed enzymes

  • @leanrial
    @leanrial 3 роки тому

    Great video!!

  • @codingwitharman5329
    @codingwitharman5329 4 роки тому

    I don't know if this is right approch but I did this and it worked.
    test("render the click event of decrement when counter is at 0", () => {
    const currentCounter = parseInt(wrapper.find("#counter-value").text());
    if (currentCounter === 0) {
    wrapper.find("#decrement-btn").simulate("click");
    }
    expect(wrapper.find("#counter-value").text()).toBe(
    currentCounter > 0
    ? (currentCounter - 1).toString()
    : currentCounter.toString()
    );
    });

  • @TheGryphon14
    @TheGryphon14 4 роки тому

    Good one. Easy to follow.

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

    That was great. However, what if we have a function that calculates some value before display, and we need to test that function?

  • @iwswordpress
    @iwswordpress 4 роки тому

    Great video. Well explained.

  • @yonimoshe9785
    @yonimoshe9785 3 роки тому

    Great tutorial

  • @HoNow222
    @HoNow222 3 роки тому

    Very nice video!

  • @ktaymour
    @ktaymour 3 роки тому

    👏 wow, thank you

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

    thank you for this awesome explanation, you make it simple and clear.
    I wondered, what is the type of terminal you use in vscode?

  • @chhumchanleak7642
    @chhumchanleak7642 3 роки тому

    Thank you so much

  • @maicongunner
    @maicongunner 5 років тому

    thanks for share this tutorial, i liked so much!

  • @80Vikram
    @80Vikram 3 роки тому

    Thanks a ton for your awesome efforts, please let me know if same techniques can be used with "React Native" as well ?

  • @MohitGupta-ln2js
    @MohitGupta-ln2js 4 роки тому

    Great video!
    I learned a lot!

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

    When working with typescript what will be the wrapper type

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

    Super

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

      So nice
      Thanks for watching, please subscribe and like this video

  • @yloibx
    @yloibx 3 роки тому

    what if we want to array for to do list? I created const [list, setList] = useState([]); but how can I test the list state when every input will added and shown?

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

    thankx buddy

  • @hadicodes
    @hadicodes 4 роки тому

    Amazing tutorial!

  • @easy_english_123
    @easy_english_123 4 роки тому

    Thanks your lecture. Beginners like me => do not install jest, just install enzyme.

  • @AnopSinghRanawatperl
    @AnopSinghRanawatperl 4 роки тому

    Thanks

  • @raosameer9323
    @raosameer9323 3 роки тому +1

    Great video.
    I have a question:
    For my particular case,
    1. I have File A with imports to File B, File C, File D
    2. I want to write the Unit tests for File A.
    3. But as soon as I import File A in FileA.spec, the imports for File B, File C, File D also get executed. This is causing me issues coz I get some null pointer exception in File C.
    4. Irrespective of what I try to do after point 3, the UT never runs those lines..
    Can you clarify on this? If the question is confusing, let me know. I will try to simplify.
    Acknowledgement appreciated

  • @5starkarma
    @5starkarma 3 роки тому +1

    Hey thanks for the tutorial! What is the VSCODE plugin you have for your font scheme?

    • @Bitfumes
      @Bitfumes  3 роки тому +1

      Material theme with fira code font and ligature enabled

  • @fernandogomez83
    @fernandogomez83 4 роки тому

    This is a great video. Thank you.

    • @Bitfumes
      @Bitfumes  4 роки тому +1

      Glad it was helpful!

    • @fernandogomez83
      @fernandogomez83 4 роки тому

      @@Bitfumes One of the best tutotials here in UA-cam.

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

    Is the mount method not working for anyone else? I had it all the way up until the end of the video. My source code is identical to his and it's having some issue with the mount method and causing all tests to fail.

  • @samerkayali4525
    @samerkayali4525 4 роки тому

    great explanation!

  • @EminoMeneko
    @EminoMeneko 3 роки тому

    I'm here because I don't know how to unit test for React.
    I started a project, and did manual testing.
    Now I start to have errors.
    I can fix them, but as of now I want to easily check for any regression.
    Lets see what you have for us here.

  • @Snugglelol
    @Snugglelol 3 роки тому

    what font were you using for VSC, it looked very nice.

  • @EmanFarrag-wb2em
    @EmanFarrag-wb2em 2 роки тому

    when using shallow with typescript it throw an error unexpexted >

  • @daryladhityahenry
    @daryladhityahenry 3 роки тому

    This is pretty nice. But I want to ask something... Is it really that slow? >__

  • @hk_build
    @hk_build 3 роки тому

    Great content Thanks..!!!
    which font family you have used for your vscode editor
    is it free please let me know i need it badly ...i am searching from long time??

  • @suvarnarao8075
    @suvarnarao8075 3 роки тому

    Can you please help me with this.
    I have to validate not null for state property when Button clicked. I tried using expect(wrapper.state().not.toBe(""). And also tried with input field id of the wrapper. But it doesn"t help.
    Could you please help how to validate an input field on the Button click event.

  • @mertgenc9890
    @mertgenc9890 3 роки тому

    whats your vscode theme?

  • @oladotunolufemi
    @oladotunolufemi 4 роки тому

    Great tutorial. What’s your vscode setup?

  • @yudokartiko9065
    @yudokartiko9065 4 роки тому +1

    Thank you

  • @laurentbajrami3688
    @laurentbajrami3688 3 роки тому

    What Font are you using!?

  • @777Vasya77
    @777Vasya77 5 років тому

    very nice video, bro, thanks

  • @bhojakrahul5880
    @bhojakrahul5880 3 роки тому

    Sir can you make for useState nd useEffect hooks with Axios call

  • @codercodercoder5977
    @codercodercoder5977 3 роки тому

    work with react 17?

  • @abhijitsil4980
    @abhijitsil4980 4 роки тому

    How to test if App component is a class based component and having state with property counter also have a callback function to increment the counter and those buttons are in a child component where those callback functions are called. Can you plaese help me on this.

  • @akmalzamri8422
    @akmalzamri8422 4 роки тому

    What's the different between toBe and toContain?