Introduction to Test Driven Development with React

  Рет қаралды 19,193

Coding With Adam

Coding With Adam

2 жыл бұрын

In this video we learn how to apply Test Driven Development(TDD) to a react application. TDD is a test first approach. That means you write a failing test first. After the test is written you write the code to make it pass.
We will create an application using TDD and the amazing part is that we will only run the application at the end of the video. We will rely on our unit tests to build a working application!
The testing library that will use is called Testing Library(testing-library.com/). When you use npx create react app it comes preloaded.
GitHub
github.com/CodingWith-Adam/td...

Пікірлер: 58
@moraisgabas
@moraisgabas Жыл бұрын
Awesome content here. Finally, a case for understanding the utility and power of TDD in clear way. Thanks, Adam.
@CodingWithAdam
@CodingWithAdam Жыл бұрын
You’re welcome! I’m really glad the tutorial helped! 😀
@joumanax
@joumanax 2 жыл бұрын
Great tutorial! I just recently found out about TDD but haven't looked into it until you posted this. Thank you for this intro! :)
@CodingWithAdam
@CodingWithAdam 2 жыл бұрын
Thank You Joumana! You're welcome. Once you get into the flow TDD it can be a lot of fun. Glad you enjoyed the tutorial.
@mj2068
@mj2068 11 ай бұрын
for someone like me that haven't thought much about tests before, it just blew my mind when the first thing you did after project creation is to run the test command.
@CodingWithAdam
@CodingWithAdam 11 ай бұрын
Thank you! It creates sense of confidence knowing that all the tests are passing. Specially when you work on a large team 😁
@keifer7813
@keifer7813 7 ай бұрын
This was great. I'd love to see more of this. Maybe a slightly more complex set of react tests to mimic a professional working environment
@CodingWithAdam
@CodingWithAdam 7 ай бұрын
Thank you!! That's a great suggestion!
@HarshSingh-ll1sq
@HarshSingh-ll1sq 7 ай бұрын
god bless you man never got so much clearity
@CodingWithAdam
@CodingWithAdam 7 ай бұрын
You’re welcome! I’m really glad that video was helpful to understand TDD with react! 😁
@midclock
@midclock 9 ай бұрын
This is an awesome explanation! Other than TDD applied to a real world example, it made me understand a little more about how React works (I used to work with Vue.js before)
@CodingWithAdam
@CodingWithAdam 9 ай бұрын
Thank you! I’m really glad the video was helpful in understanding TDD and react! 😀
@_k-nd
@_k-nd Ай бұрын
This was so very helpful, thank you!
@CodingWithAdam
@CodingWithAdam Ай бұрын
You’re welcome! Glad the video was helpful!
@lezboy5385
@lezboy5385 Жыл бұрын
Really nice tutorial, helped me a lot! Keep up the nice content, you earned a sub :)
@CodingWithAdam
@CodingWithAdam Жыл бұрын
Thank you. I’m really happy the tutorial helped! Thank you for the sub!!!
@sabarnabasak1677
@sabarnabasak1677 2 жыл бұрын
Great explaination man ! Thanks
@CodingWithAdam
@CodingWithAdam 2 жыл бұрын
Thank you! I’m glad the video helped.
@OtisDeLarge
@OtisDeLarge Жыл бұрын
I found this very helpful. Thank you.
@CodingWithAdam
@CodingWithAdam Жыл бұрын
You’re welcome! Happy the video was helpful!
@LunaSmithArt
@LunaSmithArt Жыл бұрын
A lovely introduction to TDD with React. Nicely done and simple to follow. Can you make a video with TDD/React and Typescript? Happy Halloween 🍭🎃🍬🐈‍⬛
@CodingWithAdam
@CodingWithAdam Жыл бұрын
Thank you Luna! I’m happy that enjoyed the tutorial! That’s a wonderful suggestion, I will add it to my list of future videos. Happy Halloween 🎃🐈‍⬛
@MohamedAfzalMullaTweetzal
@MohamedAfzalMullaTweetzal Жыл бұрын
Great video Adam! 💯
@CodingWithAdam
@CodingWithAdam Жыл бұрын
Thank you! Glad you liked the video. 😁
@manishamuskan6755
@manishamuskan6755 4 ай бұрын
Awesome video... One request though - Please make a video where we can test advanced features like mocking a server request, routing etc with the same TDD approach...
@CodingWithAdam
@CodingWithAdam 4 ай бұрын
Thank you for the great suggestion! I’ll consider it for a future video.
@aryanrahman3212
@aryanrahman3212 2 жыл бұрын
Great intro!
@CodingWithAdam
@CodingWithAdam 2 жыл бұрын
Thank you! Glad you enjoyed it!
@theagiletester6285
@theagiletester6285 Жыл бұрын
Very nice Adam.
@CodingWithAdam
@CodingWithAdam Жыл бұрын
Thank you! 😀
@stamatispsarras
@stamatispsarras Жыл бұрын
I am not familiar with React but this video made me understand it better, since you were building it in small steps. TDD FTW. BTW I do not understand why you had to test if you clicked twice? You never proved that this test was failing (other than when it was simply throwing an exception). In my understanding of TDD, you need to write a test completely, prove that it fails. You did that in most scenarios, but not on the ones you were checking for multiple clicks.
@CodingWithAdam
@CodingWithAdam Жыл бұрын
Agree TDD and testing in general are great and help to build confidence when changing code to ensure nothing has broken. Great question. As with any best practice like agile or TDD you can pick and chose how to use it. Testing can be about coverage and seeing if you can break anything. Clicking a button fast twice could yield an incorrect result in this situation it was an extra coverage test. We could have written the first test so that clicking the button once would hard code the value to 1. This would cause the click button twice test to fail. This can be a fun exercise to write just the code needed to make a test pass. This can be done with pair programming where one writes the test and the other makes it pass The important thing is that there is a test. As you observed with strict TDD you write the test first see the failure and make it pass. Hope this helps!
@mgcmsn
@mgcmsn Ай бұрын
Thank you sir!
@CodingWithAdam
@CodingWithAdam Ай бұрын
You’re welcome!
@matthewrideout426
@matthewrideout426 2 жыл бұрын
Thanks :)
@CodingWithAdam
@CodingWithAdam 2 жыл бұрын
You’re welcome!
@Ricardoromero4444
@Ricardoromero4444 10 ай бұрын
I mean, this shows the workflow of TDD very well... but that's kind of obvious. When you get a feature request, how do you decide what tests to write? How do you write good tests? How do you avoid writing a bunch of useless tests?
@CodingWithAdam
@CodingWithAdam 10 ай бұрын
Thanks for the question. An easy way is to use a coverage report to determine if you are executing all branches of your code ex if else etc. Also ask your self the question do my tests provide confidence that my application is working correctly? Will it prevent other devs from making mistakes. Those are a few of the things I think about.
@mks-h
@mks-h 5 ай бұрын
@@CodingWithAdam "if you are executing all branches of your code" and now the test is heavily tied to the code, which in TDD shouldn't even exist until after you write a test. Instead, I'd say you have to test all ways the component is supposed to be used (or all states it supposed to be in, and transitions between them).
@Razkazar
@Razkazar 10 ай бұрын
!
@CodingWithAdam
@CodingWithAdam 10 ай бұрын
Thank you!!! 😁
@desajustecreativo
@desajustecreativo Жыл бұрын
Writing the list of tests ahead of time breaks the second rule of TDD: “You are not allowed to write any more of a unit test than is sufficient to fail”
@CodingWithAdam
@CodingWithAdam Жыл бұрын
That’s right the 3 laws of TDD from Robert C Martin (Uncle Bob). Really helps to achieve a very high test coverage percentage 😁 butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd
@Nekenbeker
@Nekenbeker 2 ай бұрын
@@CodingWithAdam The point of doing minimal amounts of work in every step is not having great test coverage, this is merely a side product. The main point is to minimize cognitive load. If you do 10 failing tests in advance you not only have to think of the functionality you are currently implementing but also how many tests have failed before and what should my test-suite green-rate be right now. In formal TDD the whole test suite has to be green after the implementation step no matter what.
@lucasa8710
@lucasa8710 2 жыл бұрын
tnx a lot
@CodingWithAdam
@CodingWithAdam 2 жыл бұрын
You’re welcome!
@ElderESG
@ElderESG 2 жыл бұрын
What happens if you have more of the same text on the screen. Maybe make a tutorial on a more complex project. Thanks!!!
@CodingWithAdam
@CodingWithAdam 2 жыл бұрын
Great question. In that situation I would suggest using a testId. Here is the documentation testing-library.com/docs/queries/bytestid Thank you for the suggestion of making a more advanced example.
@killian_mcmillan
@killian_mcmillan 2 жыл бұрын
@@CodingWithAdam I was thinking the same thing (about using queryByText). I actually paused the video and tried to do it myself. As you said, *testId* would be the way to go (in lot of cases here), but I get it that this is more of an introduction video than building a production app. Also, I think it's better to provide the default value in the component's props, e.g.: const AwesomeCounter = ({ initialValue = 0 }) => { ...... As your component grows, it's easier to keep track of default values. Also, for preventing negative values, I would say it's nicer to write something like: const remove = () => { setCounter((prev) => prev > 0 ? prev - 1 : 0) } Just my 2 cents :) Thanks for this great video! Keep it up! I learned something new today and that's what's priceless! Cheers!
@CodingWithAdam
@CodingWithAdam 2 жыл бұрын
Thank you Killian! I’m glad you learned something new and thank you for the suggestions!
@Jrrs2007
@Jrrs2007 3 ай бұрын
Nice.
@CodingWithAdam
@CodingWithAdam 3 ай бұрын
You’re welcome!
@damindadineshimaduwagamage9044
@damindadineshimaduwagamage9044 11 ай бұрын
in TDD, how do we know if the tests are correct?
@CodingWithAdam
@CodingWithAdam 11 ай бұрын
That is a great question. One way is to use a coverage report to see if your test code is executing all paths of your code.
@Nekenbeker
@Nekenbeker 2 ай бұрын
Well the implementation tests your test. The TDD cycle is: Write a test and it must fail. Then write minimal and simplest code possible to make the test green. At this time you should know that your test is testing for your intention as it fails when the code does not what it's supposed to do but is green when the code does work. After that you refactor, i.e. make the code less stupid keeping the tested test green.
@MovaClub
@MovaClub 3 ай бұрын
many thanks!
@CodingWithAdam
@CodingWithAdam 3 ай бұрын
You’re welcome!
Test Driven Development: The best way to code that I almost never use
19:35
THIS stops 90% of C# Developers Learning TDD
19:40
Gui Ferreira
Рет қаралды 13 М.
HAPPY BIRTHDAY @mozabrick 🎉 #cat #funny
00:36
SOFIADELMONSTRO
Рет қаралды 16 МЛН
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 52 МЛН
An Ultimate Guide To BDD
18:53
Continuous Delivery
Рет қаралды 49 М.
The 3 Types of Unit Test in TDD
17:19
Continuous Delivery
Рет қаралды 100 М.
Test-Driven Development // Fun TDD Introduction with JavaScript
12:55
You might not need useEffect() ...
21:45
Academind
Рет қаралды 154 М.
Test Driven Development Tutorial For Beginners
23:54
Continuous Delivery
Рет қаралды 60 М.
The Story of Next.js
12:13
uidotdev
Рет қаралды 555 М.
Thoughts About Unit Testing | Prime Reacts
11:21
ThePrimeTime
Рет қаралды 214 М.
Why Vitest Is Better Than Jest
13:13
Web Dev Simplified
Рет қаралды 130 М.
Как бесплатно замутить игровой ноутбук
1:00
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 144 М.
Какой ноутбук взять для учёбы? #msi #rtx4090 #laptop #юмор #игровой #apple #shorts
0:18
Cheapest gaming phone? 🤭 #miniphone #smartphone #iphone #fy
0:19
Pockify™
Рет қаралды 4,1 МЛН
Самые крутые школьные гаджеты
0:49
Как распознать поддельный iPhone
0:44
PEREKUPILO
Рет қаралды 2 МЛН