<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by anri kusuma on Medium]]></title>
        <description><![CDATA[Stories by anri kusuma on Medium]]></description>
        <link>https://medium.com/@anrikusuma?source=rss-f23e1cde9b2b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1cpJOhFsGMFFuuYJF9aGDw@2x.jpeg</url>
            <title>Stories by anri kusuma on Medium</title>
            <link>https://medium.com/@anrikusuma?source=rss-f23e1cde9b2b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 00:45:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anrikusuma/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Testing Response in Angular8 using Jest]]></title>
            <link>https://medium.com/@anrikusuma/testing-response-in-angular8-using-jest-b22b44453c94?source=rss-f23e1cde9b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b22b44453c94</guid>
            <category><![CDATA[responsetesting]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[angular8]]></category>
            <dc:creator><![CDATA[anri kusuma]]></dc:creator>
            <pubDate>Sun, 15 Mar 2020 14:35:43 GMT</pubDate>
            <atom:updated>2020-03-15T14:35:43.831Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*pJLir0oNRlSg_HK_irF11w.png" /><figcaption><strong>Get your 100% coverage unit testing</strong></figcaption></figure><p>In this case, we cant just using mockReturnValue to get the response from our services. We need to spy on that. How to do that? let&#39;s get into it…</p><p>Assume we have this logic to get number</p><pre>getAllNumber = () =&gt; {</pre><pre>this.numberService.getNumber(<br>    {number:number}).subscribe(<br>    (response: CommonResponse&lt;any&gt;) =&gt; {<br>        if (response.responseStatus.responseCode == responseStatus) {<br>            const getNumber = response.data;<br>            this.getUserControl(‘ourNumber&#39;).setValue(getNumber)<br>       }}}</pre><p>And the test case should be like this</p><pre>beforeEach(inject([NumberServices], (number))</pre><p>It is to inject the service’s name and parameter in beforeEach to spyOn our service. NumberServices is the token and number as the parameter.</p><pre>numberService= number</pre><p>Assign the parameter to an object</p><pre>spyOn(numberService, ‘getAllNumber&#39;).and.returnValue(of({</pre><pre>=&gt;  call it using spyOn(object, ‘method’)</pre><pre>/**<br> * Install a spy onto an existing object.<br> * @param object The object upon which to install the `Spy`.<br> * @param method The name of the method to replace with a `Spy`.<br> */</pre><p>what what we want to do is to simulate the service get the success response which is ’00’. Hence, use the and.returnValue(of({}) then inside of returnValue write the value that you want to</p><pre>responseStatus: {</pre><pre>responseCode: &#39;00&#39;<br>        },<br>        data: [{<br>            number: &#39;036&#39;<br>        }]</pre><p>Here, the complete test case</p><pre>let numberService;</pre><pre>beforeEach(inject([NumberServices], (number) =&gt; {<br>    NumberServices = numberService<br>    spyOn(numberService, ‘getAllNumber&#39;).and.returnValue(of({</pre><pre>responseStatus: {</pre><pre>responseCode: &#39;00&#39;<br>        },<br>        data: [{<br>            number: &#39;036&#39;<br>        }]<br>    }));<br><br>    fixture = TestBed.createComponent(NumberComponent);<br>    component = fixture.debugElement.componentInstance;<br>    fixture.detectChanges();<br>}));</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b22b44453c94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Test-Driven Development (TDD): Quick Overview with Example]]></title>
            <link>https://medium.com/@anrikusuma/test-driven-development-tdd-quick-overview-with-example-9ffaa56af8c0?source=rss-f23e1cde9b2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ffaa56af8c0</guid>
            <category><![CDATA[test-driven-development]]></category>
            <category><![CDATA[tdd]]></category>
            <dc:creator><![CDATA[anri kusuma]]></dc:creator>
            <pubDate>Sun, 29 Dec 2019 07:22:48 GMT</pubDate>
            <atom:updated>2019-12-29T07:22:48.293Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lrBKqGRjp32BdnmlItyEDQ.png" /></figure><p>A lot of engineers start to build a program with TDD concepts. Actually, it’s hard to change the habit. Commonly, we create a program based on requirements and directly code it. In TDD we cant do that, we need to write the test case first, which means it will guide us to the right requirement and minimizing the bug.</p><p>TDD has three main steps that are red, green and refactors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*kMPpEmP9u7qGw_Ih6FHQpA.png" /><figcaption>TDD cycle</figcaption></figure><p><strong>Red</strong>: write a test and make it fail.</p><p><strong>Green</strong>: write the test that makes the test past, just make a simple test case.</p><p><strong>Refactor</strong>: improve your code and don’t change the behavior. make sure the test pass.</p><p>The basic habit that we need to build using TDD is to try to breakdown our requirements. Then, make the simple of a test case, we could name it a baby step. Just strick to the smallest requirement, keep in your mind the TDD cycle steps.</p><p>Beforehand, I found the blocker through this concept, which is a habit. It is really hard to change the habit. But, enjoy it! cause it is very useful to make good code and keep us strick to the requirement to avoid “<strong>YAGNI- YOU AIN’T GONNA NEED IT</strong>”.</p><p>let’s go through the example!</p><p>The requirements: Given a string representing a matrix of numbers, return the rows and columns of that matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Hy4Ki9ByKmr5XEI9IygiA.png" /><figcaption>Easy practice example from exercism</figcaption></figure><p>through the requirement, we could design our first like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rpBWGh3qmHZKswEGVYDC3Q.png" /><figcaption>First test case</figcaption></figure><p>First, it will fail cause we didn&#39;t write the code yet.</p><p>and the second is to make the test pass, which means in the green cycle. However, we need to write the logic and run the test again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vVlK2-uqPyX7tD_sXdH_Mw.png" /><figcaption>Implementation of the first test case</figcaption></figure><p>Then, we go to the refactoring cycle which means evaluate our code, is it good code enough? by following <strong>Four Principles Of Simple Design.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ffaa56af8c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>