<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alfredo Narváez Docimo</title>
    <description>The latest articles on DEV Community by Alfredo Narváez Docimo (@alfdocimo).</description>
    <link>https://dev.to/alfdocimo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F245332%2Fd4953c3f-c260-4a7b-beac-029f2af9aaae.jpeg</url>
      <title>DEV Community: Alfredo Narváez Docimo</title>
      <link>https://dev.to/alfdocimo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alfdocimo"/>
    <language>en</language>
    <item>
      <title>Here's how Next.js helped me build and deploy an MVP in a week </title>
      <dc:creator>Alfredo Narváez Docimo</dc:creator>
      <pubDate>Fri, 05 Jun 2020 12:39:48 +0000</pubDate>
      <link>https://dev.to/alfdocimo/here-s-how-next-js-helped-me-build-and-deploy-an-mvp-in-a-week-2c3</link>
      <guid>https://dev.to/alfdocimo/here-s-how-next-js-helped-me-build-and-deploy-an-mvp-in-a-week-2c3</guid>
      <description>&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@giabyte?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Gia Oris&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/start?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Gratitude&lt;/em&gt; is a beautiful thing. Specially when it comes from someone who means a lot to you. I had this idea of having a way to put a smile on somebody's face in only two clicks. It shouldn't take a lot of time to say things like &lt;em&gt;"great work on this!"&lt;/em&gt; and, to be honest, we can always use pick-me-ups for motivation to keep us moving forward.&lt;/p&gt;

&lt;p&gt;One day, I was looking for open API's to mess around with and I stumbled upon an API to tell someone off, which was fun. But then it clicked - instead of telling someone off - &lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  What if... we could have &lt;em&gt;kudos&lt;/em&gt;... as a service?
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;p&gt;And thus, &lt;a href="https://kuaas.com/" rel="noopener noreferrer"&gt;https://kuaas.com/&lt;/a&gt; was born.&lt;/p&gt;

&lt;p&gt;The idea got stuck on my head - and it was there for weeks. I decided to create a github repository just to look at it and remind myself to come back to it and actually implement it.&lt;/p&gt;

&lt;p&gt;A good friend of mine introduced me to &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;Next.js&lt;/a&gt; a week prior to this. I was skeptical at first. I heard good things about it, but I had other way of doing things. Me, being a javascript enthusiast and a react advocate - decided to give it a try, and boy I can say that this was a turning point for me 🚀&lt;/p&gt;

&lt;p&gt;In around 30 minutes I was up and running. And this is because of how amazingly well documented it is.&lt;/p&gt;

&lt;p&gt;Okay, let's break down the days:&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 1
&lt;/h2&gt;

&lt;p&gt;Ready, set, go! 🏃‍♀️🏃‍♂️&lt;/p&gt;

&lt;p&gt;I was very excited to actually start. Even though I work fulltime as a SE I still had enough motivation to keep me pushing through and work on this project during the week. First thing I did was to set up a new Notion page with all the things I wanted the app to have. From those - I actually just prioritized enough to have this working as an MVP. After filling the board with tasks and ideas - and my mug with some coffee - I decided it was time to actually work on some visual prototype. Since this was all about experimentation I decided to go with something new for CSS. I ended up picking Tailwind as it had everything I was looking for to setup things quickly and start building my UI.&lt;/p&gt;

&lt;p&gt;This is a screenshot from what that initial design looked like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4zecfhzrv2k1h007sf1m.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4zecfhzrv2k1h007sf1m.jpg" alt="Figma Design"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From this moment on - I was full on coding 💻&lt;/p&gt;

&lt;p&gt;I knew that I didn't just want to have this working as a web app, I also wanted to expose an API. And Nextjs had just the thing for that: &lt;a href="https://swr.now.sh/" rel="noopener noreferrer"&gt;SWR&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  API implementation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/alfdocimo/kuaas/commit/cdc0f77d4d287a5bd59ec606cc428d8a73d6888d" rel="noopener noreferrer"&gt;Git commit&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So for a &lt;code&gt;v1&lt;/code&gt; or &lt;code&gt;MVP&lt;/code&gt; I wanted to keep it very simple. You send in a name, and a subject to give kudos about. The service will then map your subject to a random message add in the name, and send it back.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But hey, heres a little secret. I love gifs&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Then it hit me. Let's integrate this with the GIPHY API! I set up for a dev account and got my API key. Tried a couple methods and then realized that they actually had a &lt;code&gt;random&lt;/code&gt; method. I 👏 got 👏 so 👏 happy. This is just what I wanted. See, the idea behind the app is not to include a custom curated message &lt;em&gt;(which I actually later implemented)&lt;/em&gt; but the fact that in two clicks you could send a random message along with a Gif to someone. And randomness actually helps on this. It takes out the time you dedicate to select the perfect gif and the perfect message. Okay, back to the API. So now I had this GIPHY integration and I was able to send back a random kudos message based on a subject along with a gif. Yay! but hey - I thought - maybe you &lt;em&gt;do&lt;/em&gt; want to customize the message a bit and also select what filter to use to retrieve the gif you want. So I went ahead and implemented a way to send a custom message and also send in a filter for the gif.&lt;/p&gt;

&lt;h3&gt;
  
  
  UI implementation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/alfdocimo/kuaas/commit/c73ea8bfdf26bb4bd577f5e5080290466c16cea2" rel="noopener noreferrer"&gt;Git commit&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I decided to stay true to my original "design" (I'm sorry to all the designers reading/looking at this. I did my best, I don't know how you guys make things look so good - here's to you 🍷) and just base all the app on this one centered card. This was pretty straight forward - I just looked up the Tailwind docs and started playing around with utility classes until my UI looked someone acceptable.&lt;/p&gt;

&lt;h2&gt;
  
  
  UI and API integration
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/alfdocimo/kuaas/commit/c2906be2fe3be74e1ea7319f46e459a81a123aa3" rel="noopener noreferrer"&gt;Git commit&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember about &lt;code&gt;SWR&lt;/code&gt;? Well this is the part where I implemented it that. And, no joke - it worked on the first try. This was amazing. I was able to fetch remotely the API I had defined.&lt;/p&gt;

&lt;p&gt;And thus - concludes day 1.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 2
&lt;/h2&gt;

&lt;p&gt;Building upon the MVP.&lt;/p&gt;

&lt;p&gt;Okay - I already had a UI, my API and the GIPHY integration, so this day I was pretty chill. I actually just did some minor refactoring, and some UI tweaks here and there. I also added a footer in there. &lt;a href="https://github.com/alfdocimo/kuaas/commit/56fd64eef25a7ae834cb6075bd020f89dc747be0" rel="noopener noreferrer"&gt;Git commit&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That was actually it for day 2. I decided to get some sleep and tackle other things tomorrow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 3
&lt;/h2&gt;

&lt;p&gt;This day was pretty interesting! I was very inspired and decided to actually do something most people begin with. Buy a domain! 😅&lt;/p&gt;

&lt;p&gt;Turns out &lt;a href="https://vercel.com/" rel="noopener noreferrer"&gt;Vercel&lt;/a&gt; allows you to buy a domain through their platform. And then you just assign it to a project and that's it! You now have your project deployed on your domain.&lt;/p&gt;

&lt;p&gt;Now, I had some things in mind for today since by the end of the day I was actually gonna be sending this to friends to try it. So we can count this as the "last day"&lt;/p&gt;

&lt;h3&gt;
  
  
  Google Analytics Integration
&lt;/h3&gt;

&lt;p&gt;Since I added a domain, I actually wanted to get some analytics in there also. So I integrated GA in there &lt;a href="https://github.com/alfdocimo/kuaas/commit/4e72dc993f6578639848830af029bfdfedaf3654" rel="noopener noreferrer"&gt;Git commit&lt;/a&gt;&lt;br&gt;
After playing around with NordVPN I realized it was working properly. Yay!&lt;/p&gt;

&lt;h3&gt;
  
  
  Interaction
&lt;/h3&gt;

&lt;p&gt;I felt like something was lacking. Something like:&lt;/p&gt;

&lt;p&gt;👉 A go back button/link&lt;/p&gt;

&lt;p&gt;👉 A copy url to clipboard button/link&lt;/p&gt;

&lt;p&gt;👉 Share on social media buttons/links&lt;/p&gt;

&lt;p&gt;The first two were actually pretty straight forward to implement. Its the third one where I was a bit lost and really struck gold when I found &lt;a href="https://www.npmjs.com/package/react-share" rel="noopener noreferrer"&gt;react-share&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this was it. I had a fully functional MVP that I was happy with 😊&lt;/p&gt;

&lt;p&gt;Last thing I did was add some basic &lt;code&gt;docs&lt;/code&gt; on how to consume &lt;code&gt;/api/v1&lt;/code&gt; from an external service.&lt;/p&gt;

&lt;p&gt;Finally deployed that through Vercel, and saw my app live. It was pretty amazing seeing people actually go in there and send each other URLs with kudos messages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 4
&lt;/h2&gt;

&lt;p&gt;Went out for drinks with friends to celebrate! 🍻&lt;/p&gt;

&lt;p&gt;&lt;em&gt;disclaimer: COVID-19 Lockdown is being lifted in Spain. Stay safe, please!&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 5
&lt;/h2&gt;

&lt;p&gt;Write a &lt;code&gt;dev.to&lt;/code&gt; post on how excited you are about actually concluding this intense but rewarding week.&lt;/p&gt;

&lt;p&gt;Thank you so much for taking the time to read. Every bit of feedback helps! 🙏&lt;/p&gt;

&lt;p&gt;Also, if you feel like contributing and/or opening issues you're more than welcome!&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/alfdocimo/kuaas/blob/master/CONTRIBUTING.md" rel="noopener noreferrer"&gt;Contributing&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/alfdocimo/kuaas" rel="noopener noreferrer"&gt;Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Stay awesome 💜&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>architecture</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Unit testing &amp; integration explained with math functions </title>
      <dc:creator>Alfredo Narváez Docimo</dc:creator>
      <pubDate>Sat, 16 May 2020 20:31:41 +0000</pubDate>
      <link>https://dev.to/alfdocimo/unit-testing-integration-explained-with-math-functions-163g</link>
      <guid>https://dev.to/alfdocimo/unit-testing-integration-explained-with-math-functions-163g</guid>
      <description>&lt;p&gt;In this quick post, I hope to explain with some common math abstraction how I perceive Unit testing and Integration testing.&lt;/p&gt;

&lt;p&gt;Disclaimer: &lt;em&gt;This is post is only meant to provide the notions behind testing, is not meant to be an in-depth testing explanation&lt;/em&gt; 😛&lt;/p&gt;

&lt;p&gt;Okay, you must be asking yourself, why? I mean, not all coding is created equal, and let's be honest - you don't really need to understand math to code. However, I do believe that - and this comes from someone who flunked calculus and algebra numerous times in college - math is fascinating and a great tool to explain concepts in a simple manner. &lt;/p&gt;

&lt;h1&gt;
  
  
  First of all - what is a function? 📦
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;A function is a process or a relation that associates each element x of a set X, the domain of the function, to a single element y of another set Y&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I can't find a better definition than to look at it as a black box. A function is a &lt;em&gt;black box&lt;/em&gt; that, when given a value, will return something else.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T2ksfmXT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Function_machine2.svg/480px-Function_machine2.svg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T2ksfmXT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Function_machine2.svg/480px-Function_machine2.svg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://en.wikipedia.org/wiki/Function_(mathematics)"&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, cool - that's as much math as you need to know for what's next!&lt;/p&gt;

&lt;p&gt;So here's the thing, we want to test functions. We want to make sure they return the correct value each time they're called. We have this first function &lt;code&gt;f(x)&lt;/code&gt; which returns the given number &lt;code&gt;x&lt;/code&gt; plus one. Then, we have &lt;code&gt;g(x, y)&lt;/code&gt; which does a bit more, it returns the sum of &lt;code&gt;x&lt;/code&gt; plus the result of &lt;code&gt;f(y)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m4QL8Dwx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rzz0dn5e6h6td2jk29lw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m4QL8Dwx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rzz0dn5e6h6td2jk29lw.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What's going on here? we have one function &lt;code&gt;f(x)&lt;/code&gt; that we can test by itself as it has no dependency on another function. This is what we can consider something that can be tested as a unit.&lt;/p&gt;

&lt;p&gt;Then, there's another function &lt;code&gt;g(x, y)&lt;/code&gt; which implements &lt;code&gt;f(x)&lt;/code&gt;. It needs &lt;code&gt;f(x)&lt;/code&gt; to produce a value. It is directly dependant and therefore needs this other function to live. &lt;em&gt;Nothing like a math love story.&lt;/em&gt; 💙 &lt;/p&gt;

&lt;h1&gt;
  
  
  Coding the functions 💻
&lt;/h1&gt;

&lt;p&gt;So in order to actually test this, we would have to, you know, code these functions. You can use your language of choice but as the JavaScript fan I am, I highly encourage you to use js 💛&lt;/p&gt;

&lt;p&gt;So for both functions, we will end up having something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fEYj3pF_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rjeqg3vxraynxhmq6px1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fEYj3pF_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rjeqg3vxraynxhmq6px1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Getting into the tests 🧪️
&lt;/h1&gt;

&lt;p&gt;Now that we have coded our functions, we want to test this first function &lt;code&gt;f(x)&lt;/code&gt; and make sure that it returns the correct value for &lt;code&gt;x = 1&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uTl4oIFb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/l37s5qh4tfq2hwx852g1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uTl4oIFb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/l37s5qh4tfq2hwx852g1.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We also want to test that &lt;code&gt;g(x, y)&lt;/code&gt; returns a correct value for &lt;code&gt;x = 2 ; y = 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YZ2dcZ6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u3kfubrn07k4y4lsuaw7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YZ2dcZ6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u3kfubrn07k4y4lsuaw7.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will be using &lt;em&gt;Jest&lt;/em&gt; for these examples, if you still don't know about &lt;a href="https://jestjs.io/"&gt;Jest&lt;/a&gt;, give it a shot, it's an amazing testing framework for js!&lt;/p&gt;

&lt;p&gt;So for the following &lt;a href="https://en.wikipedia.org/wiki/Test_suite"&gt;test suite&lt;/a&gt; We will be expecting that when we call these functions with the params described above, they should actually return what we expect.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k5xI0JmY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8orl66vx91a2qb3nq9bp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k5xI0JmY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8orl66vx91a2qb3nq9bp.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;One thing to highlight here is that by testing &lt;code&gt;g(x, y)&lt;/code&gt; we are implicitly testing &lt;code&gt;f(x)&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Mocking 🃏
&lt;/h1&gt;

&lt;p&gt;Can we test &lt;code&gt;g(x, y)&lt;/code&gt; as a unit? Up until now we now that &lt;code&gt;g(x, y)&lt;/code&gt; depends on &lt;code&gt;f(x)&lt;/code&gt;, so its result will be bound to the result of &lt;code&gt;f(x)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;...or will it? 🤔&lt;/p&gt;

&lt;p&gt;Mock is a very interesting concept when it comes to testing. For some controversial, for some a helpful tool. I am not here to discuss this, but rather give you the notion of what mocking is, and how we &lt;em&gt;could&lt;/em&gt; use it to test &lt;code&gt;g(x, y)&lt;/code&gt; without any dependencies.&lt;/p&gt;

&lt;p&gt;With mocking you can override, substitute, manage things that should be out of your control. In this example, because of how &lt;code&gt;g(x, y)&lt;/code&gt; is built, we should not be able to look inside our &lt;code&gt;black box&lt;/code&gt; and replace &lt;code&gt;f(x)&lt;/code&gt; with something else.&lt;/p&gt;

&lt;p&gt;This is where &lt;em&gt;mocking&lt;/em&gt; comes in. In an uncontrolled environment, it allows you to open up the &lt;code&gt;black box&lt;/code&gt; and substitute parts of how the system behaves to your will.&lt;/p&gt;

&lt;p&gt;It would be the equivalent to doing something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iHivIJ_C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y7mhjjj5aiynhlo2nung.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iHivIJ_C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y7mhjjj5aiynhlo2nung.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, because we have tampered with &lt;code&gt;g(x, y)&lt;/code&gt;'s black box, it will produce a new output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_G7RlJoB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ffew13lsuvjx8cfbi0l7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_G7RlJoB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ffew13lsuvjx8cfbi0l7.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Compare that to the example above, in which we don't have access to the black box&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YZ2dcZ6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u3kfubrn07k4y4lsuaw7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YZ2dcZ6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u3kfubrn07k4y4lsuaw7.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are not equal scenarios, hence why researching how to mock properly is something worth investing some time in!&lt;/p&gt;

&lt;p&gt;So then - can we test &lt;code&gt;g(x, y)&lt;/code&gt; in isolation? as a unit?&lt;/p&gt;

&lt;p&gt;Yes! - Jest offers a lot of functionality for mocking&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--otGo_pRs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/udksmf8ij74w2j1uojek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--otGo_pRs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/udksmf8ij74w2j1uojek.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;⚠️ &lt;em&gt;Should you test &lt;code&gt;g(x, y)&lt;/code&gt; in isolation?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It depends - are you testing edge cases? is &lt;code&gt;f(x)&lt;/code&gt; an external dependency out of your control? There are a lot of things to keep in mind before mocking.&lt;/p&gt;

&lt;p&gt;So that's it! A basic introduction to testing explained with math functions.&lt;/p&gt;

&lt;p&gt;Hope you liked this post - keep hacking! 🔥&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>testing</category>
      <category>functional</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
