<?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[KhojChakra - Medium]]></title>
        <description><![CDATA[Follow us for knowledge, code and other stuff - Medium]]></description>
        <link>https://medium.com/khojchakra?source=rss----49a2246aeb46---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>KhojChakra - Medium</title>
            <link>https://medium.com/khojchakra?source=rss----49a2246aeb46---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 19:53:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/khojchakra" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding Short-circuit Evaluation in Javascript]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/khojchakra/understanding-short-circuit-evaluation-in-javascript-31b5770a41f7?source=rss----49a2246aeb46---4"><img src="https://cdn-images-1.medium.com/max/674/1*ajz4Go1jHmlzD2BIDv2YVg.jpeg" width="674"></a></p><p class="medium-feed-snippet">Explore about Short-circuiting in Javascript to make your code clean and beautiful.</p><p class="medium-feed-link"><a href="https://medium.com/khojchakra/understanding-short-circuit-evaluation-in-javascript-31b5770a41f7?source=rss----49a2246aeb46---4">Continue reading on KhojChakra »</a></p></div>]]></description>
            <link>https://medium.com/khojchakra/understanding-short-circuit-evaluation-in-javascript-31b5770a41f7?source=rss----49a2246aeb46---4</link>
            <guid isPermaLink="false">https://medium.com/p/31b5770a41f7</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Gurseerat Kaur]]></dc:creator>
            <pubDate>Sat, 24 Oct 2020 15:41:31 GMT</pubDate>
            <atom:updated>2020-10-27T16:52:44.201Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Worker Threads in Node JS]]></title>
            <link>https://medium.com/khojchakra/worker-threads-in-node-js-9021be83e3d1?source=rss----49a2246aeb46---4</link>
            <guid isPermaLink="false">https://medium.com/p/9021be83e3d1</guid>
            <category><![CDATA[cpu-utilization]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Saurabh Kumar]]></dc:creator>
            <pubDate>Sat, 26 Sep 2020 10:32:45 GMT</pubDate>
            <atom:updated>2020-09-26T10:32:45.359Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*NEKjA3JhvHKqW-EJAP9hHg.jpeg" /></figure><blockquote><strong>is Node JS became multi-threaded now..??</strong></blockquote><p>it’s a first question lot of people, who are new to Node JS, ask me when they came to know about worker threads in node and answer is <strong>NO..!!</strong></p><p>let&#39;s try to understand, why the node js is still single-threaded even though it has worker thread. even before that we need to understand what the worker thread is..??</p><p>worker thread module in node js is based on Web Workers that are available in the browsers and are a simple means for web content to run scripts in background threads.</p><p>As per the Node documentation, The worker_threads module enables the use of threads that execute JavaScript in parallel. To access it:</p><pre>const worker = require(&#39;worker_threads&#39;);</pre><p><em>Workers (threads) are useful for performing CPU-intensive JavaScript operations. They will not help much with I/O-intensive work. Node.js’s built-in asynchronous I/O operations are more efficient than Workers can be.</em></p><p>Unlike child_process or cluster, worker_threads can share memory. They do so by transferring ArrayBuffer instances or sharing SharedArrayBuffer instances.</p><p>worker thread provides you APIs to deal with CPU intensive tasks while still maintaining the responsive application</p><p>it gives CPU intensive workload to another thread while keeping your main thread available for new user request</p><p>each worker thread is the new instance of the event loop, creating a worker thread gives you a new event loop, so the event loop running in the main thread is free to take new request if you run CPU intensive task in a worker thread. one good thing is if any worker thread running out of memory then it will not take down other worker thread</p><p>worker threads don’t have all the mechanism for thread synchronization like in other multi-threaded programming languages, however, we can pass messages back and forth between a worker thread and the main thread.</p><p>Now let&#39;s see how a worker thread can take the load off the main thread and keep your app responsive. Below is the minimal example of worker thread in action</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1c846be57bea0efd6cabba331c97b91/href">https://medium.com/media/c1c846be57bea0efd6cabba331c97b91/href</a></iframe><p>here from the above code, you can see that we can instantiate a new worker from Worker constructor. isMainThread check if it is the main thread. The worker thread will begin it’s execution once instantiate. parentPort is a communication port back to the main thread. It is also an event emitter. Whatever you passed, the Post message will be passed as a message event back to the main thread. The name of the event sent across the parent port is message . we have added an event handler in the main thread, which will for now just log the message received from a worker thread.</p><p>okay..!! let’s now run the above code and see how it works. below I have attached the screenshot from my machine, you can compare it with your output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*kgj0KuO-LtMDb4whAV3H0w.png" /></figure><p>here you can observe that the main event loop was not blocked because of the worker thread doing some CPU intensive task. we immediately get the output from the main thread. the message is passed back from the worker got handled and logged later, the cpuIntensiveTask function is still blocking an event loop. It is blocking the Worker’s event loop, which left the main event loop free, to continue processing the user’s request.</p><p>here we saw how we can pass messages from the worker thread to the main thread. now let’s see how we can pass data along with the messages from the main thread to the worker thread.</p><p>for that, we have to importworkerData from worker_thread then use it to pass data to the worker by passing an object to the worker constructor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70199f710a0533013381b3d3faadfa61/href">https://medium.com/media/70199f710a0533013381b3d3faadfa61/href</a></iframe><p>below is the output you will get when you run the above code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*Ab2zS3moli6nOR08AO92Hw.png" /></figure><p>I hope i was able to give some idea about worker_threads always remember that worker_thread is only meant to be used for <strong>CPU intensive task..!!</strong></p><p>please clap 👏 if you found this article useful. cheers 🍺</p><h3>About the Author</h3><p><a href="https://sk-cse.github.io/">Saurabh Kumar</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9021be83e3d1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/khojchakra/worker-threads-in-node-js-9021be83e3d1">Worker Threads in Node JS</a> was originally published in <a href="https://medium.com/khojchakra">KhojChakra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript features that every Web Developer should know]]></title>
            <link>https://medium.com/khojchakra/javascript-features-that-every-web-developer-should-know-45ed6cb4f7b2?source=rss----49a2246aeb46---4</link>
            <guid isPermaLink="false">https://medium.com/p/45ed6cb4f7b2</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Gurseerat Kaur]]></dc:creator>
            <pubDate>Sun, 20 Sep 2020 03:59:49 GMT</pubDate>
            <atom:updated>2020-09-20T03:59:49.158Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Explore the new Javascript features for faster development.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*XUm7QY1ceJJHEL87tRYMUQ.jpeg" /></figure><p>In recent years, Javascript has emerged as a giant in web development. Each year, a new version of ECMAScript is released, the latest one being ECMAScript2020 (ES11). With the emergence of various JS frameworks like Angular, ReactJs, VueJs, NodeJs etc, the need to keep adapting to the newer javascript features has increased.</p><p>In this post, I’ve made a compilation of all the new topics in Javascript that I feel every web developer should know. These topics range between ES6 and ES11.</p><h3>Rest and Spread Operators</h3><h4>Rest Parameters</h4><p>With the <strong>rest parameter</strong>, we can represent an indefinite number of arguments as an array. We can pass the arguments in the function prefixed with ... and this will cause all the arguments to be placed within an array.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters">(You can read more about it here)</a></p><pre>function getArgs(x, y, ...otherNum) {<br>  console.log(&quot;x&quot;, x)<br>  console.log(&quot;y&quot;, y)<br>  console.log(&quot;otherNum&quot;, otherNum)<br>}</pre><pre>getArgs(1, 2, 3, 4, 5);<br>// expected output: <br>// x, 1<br>// y, 2<br>// otherNum, [3, 4]</pre><h4>Spread Operator</h4><p>The <strong>spread operator</strong> allows expanding an array or an object. It is the reverse of rest parameters i.e. it can be used in function calls instead of function definitions. It can be used for merging arrays, copying array, add elements to an array, or passing array elements etc, in a function call.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax">(You can read more about it here)</a></p><pre>var foo = [1, 2, 3, 4];<br>var bar = [...foo, 5, 6];<br>console.log(bar);</pre><pre>// expected output: [1, 2, 3, 4, 5, 6]</pre><h3>Destructuring Assignment</h3><p>The <strong>destructuring assignment</strong> syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">(You can read more about it here)</a></p><pre>[a, b] = [1, 2];<br>console.log(a); // 1<br>console.log(b); // 2</pre><pre>// Swap two variables<br>[a, b] = [b, a];<br>console.log(a); // 2<br>console.log(b); // 1</pre><pre>[firstName, lastName] = &quot;Gurseerat Kaur&quot;.split(&quot; &quot;);<br>console.log(firstName) // &quot;Gurseerat&quot;<br>console.log(lastName) // &quot;Kaur&quot;</pre><h3>Nullish Coalescing</h3><p>The <strong>nullish coalescing operator (</strong><strong>??)</strong> is a logical operator that returns its right-hand side operand when its left-hand side operand is<strong> null </strong>or <strong>undefined</strong>, and otherwise returns its left-hand side operand.</p><p>In logical OR operator(||), the right-hand side operand is returned when the left-hand side operand is false, 0, null or undefined.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator">(You can read more about it here)</a></p><pre>var defaultVal = false;<br>console.log(defaultVal ?? &#39;foo&#39;); // false<br>console.log(defaultVal ||&#39;bar&#39;); // bar</pre><h3>Optional chaining</h3><p>By using <strong>optional chaining</strong>, we can read the value of a property that is deeply stored in an object without validating each reference in the chain. We’ve often encountered the error, <em>“TypeError: Cannot read property ‘value’ of undefined”. </em>We now have an option to access the value by using <strong>?.</strong></p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining">(You can read more about it here)</a></p><pre>// Traditional Way<br>if(this.object &amp;&amp; this.object.key1 &amp;&amp; this.object.key1.key2) {<br>  value = this.object.key1.key2;<br>}</pre><pre>// Optional Chaining<br>value = this.object?.key1?.key2;</pre><h3>Dynamic Import</h3><p>The static import in javascript evaluates all the code during the load time, whereas, in <strong>dynamic import</strong>, we can import the modules on-demand or conditionally.</p><p><a href="https://javascript.info/modules-dynamic-imports">(You can read more about it here)</a></p><pre>import(&#39;/path/to/my-file.js&#39;)<br>  .then((func) =&gt; {<br>    // Do something with the module.<br>  });</pre><pre>// Using with await<br>let module = await import(&#39;/path/to/my-file.js&#39;);</pre><h3>Short Circuit Evaluation</h3><p>In short circuit evaluation, expressions with logical AND (&amp;&amp;) and OR (||) operators are evaluated from left to right.</p><p><strong>For &amp;&amp; operator, </strong>if<strong> </strong>the first expression evaluates to false then the whole expression will be false and the rest of the expressions will not be evaluated.</p><p><strong>For || operator,</strong> if the first expression evaluates to true then the whole expression will be true and the rest of the expressions will not be evaluated.</p><pre>var val = 20;  <br>val == 20 &amp;&amp; doSomething(); <br>// if (val == 20) doSomething();</pre><pre>val == 10|| doSomething(); <br>// if (val != 10) doSomething();</pre><p>Let’s take another example,</p><pre>var x = 150;<br>var value = (x &lt; 100 &amp;&amp; &#39;Below 100&#39;) || (x &gt; 200 &amp;&amp; &#39;Above 200&#39;) || &#39;Between 100-200&#39;;<br>console.log(value);<br>// expected output: &#39;Between 100-200&#39;</pre><h3><strong>Comma operator</strong></h3><p>The comma operator(,) evaluates each of its operands from left to right and then returns the value of the right operand. We have to add the expressions wrapped inside parentheses and separated with commas (<em>expr1, expr2</em>) for the comma operator to work.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator">(You can read more about it here)</a></p><pre>var a = 0; <br>var b = ( a++, 2 ); </pre><pre>console.log(a);  // 1<br>console.log(b);  // 2</pre><p>In this post, we’ve covered many useful topics in Javascript. These features will really help you in faster development and reduce your code lines. If you have any queries, ask them in the response section. Hope you found the post helpful.</p><p>Happy Coding! 😄</p><h3>References</h3><ol><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript">https://developer.mozilla.org/en-US/docs/Web/JavaScript</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45ed6cb4f7b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/khojchakra/javascript-features-that-every-web-developer-should-know-45ed6cb4f7b2">Javascript features that every Web Developer should know</a> was originally published in <a href="https://medium.com/khojchakra">KhojChakra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developer’s Guide to Unit Testing in Angular — Part 3 (Resolving Dependencies)]]></title>
            <link>https://medium.com/khojchakra/developers-guide-to-unit-testing-in-angular-part-3-resolving-dependencies-b1738be574ac?source=rss----49a2246aeb46---4</link>
            <guid isPermaLink="false">https://medium.com/p/b1738be574ac</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <dc:creator><![CDATA[Gurseerat Kaur]]></dc:creator>
            <pubDate>Mon, 14 Sep 2020 05:27:53 GMT</pubDate>
            <atom:updated>2020-09-14T05:27:53.616Z</atom:updated>
            <content:encoded><![CDATA[<h3>Developer’s Guide to Unit Testing in Angular — Part 3 (Resolving Dependencies)</h3><p><em>Explore how to write test cases for components and services with dependencies.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*3JZIsiEkzSsXLDN21aZAQg.jpeg" /></figure><p>The whole idea of unit testing is to test each piece of code in an isolated system. But what if that piece of code is dependant on any service or component. What do we do then? Let’s dive into this question in this article. Points covered here are:</p><ol><li>Component’s dependency on another component</li><li>Service’s dependency in a component or on another service</li><li>Windows Property</li></ol><p>If you are new to unit testing and want to learn how to set up your unit testing environment and write test cases for components, read our first guide here: <a href="https://medium.com/khojchakra/developers-guide-to-unit-testing-in-angular-part-1-6a5821a80d0a">Developer’s Guide to Unit Testing in Angular — Part 1</a>.</p><p>If you want to learn how to write test cases for services, pipes, and directives, read our second guide here: <a href="https://medium.com/khojchakra/developers-guide-to-unit-testing-in-angular-part-2-services-pipes-directives-f1045495f98e">Developer’s Guide to Unit Testing in Angular — Part 2 (Services, Pipes, Directives)</a>.</p><h3>Component’s Dependency on another Component</h3><p>In Angular, a component can have a dependency on a child component. Let’s create a parent component, that calls a child component inside it with a condition.</p><p><strong>parent.component.html</strong></p><pre>&lt;app-child *ngIf=&quot;showChild&quot;&gt;&lt;/app-child&gt;</pre><p><strong>parent.component.ts</strong></p><pre>export class ParentComponent implements OnInit {</pre><pre>  @ViewChild(ChildComponent, {static: false}) childComponent: ChildComponent;</pre><pre>  showChild: boolean;</pre><pre>  constructor() { }</pre><pre>ngOnInit() {<br>    this.childComponent.getData();<br>  }</pre><pre>}</pre><p>Now, when we run the command ng test in the terminal, Karma will open the browser window and start running the test cases. But, we’ll get the error like in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*o4iLdaaOsIjIrF_Cjj8y2w.png" /></figure><p>Here, as you can see, we’re getting the error <strong>‘app-child’ is not a known element. </strong>To make this element known, we can’t call the actual child component because this beats the whole purpose of “isolated system”.</p><p>Instead, we’ll create a mock component in our spec.ts file or we can create a mock component file and then import it inside the spec.ts file.</p><p><strong>parent.component.spec.ts</strong></p><pre>import { async, ComponentFixture, TestBed } from &#39;@angular/core/testing&#39;;<br>import { ParentComponent } from &#39;./parent.component&#39;;<br>import { ChildComponent } from &#39;../child/child.component&#39;;<br>import { Component } from &#39;@angular/core&#39;;<br>import { By } from &#39;@angular/platform-browser&#39;;</pre><pre>@Component({<br>  selector: &#39;app-child&#39;,<br>  template: &#39;&lt;p&gt;Mock Child Component&lt;/p&gt;&#39;,<br>  <strong>providers</strong>: [{<br>    provide: ChildComponent,<br>    <strong>useClass</strong>: MockChildComponent<br>  }]<br>})</pre><pre>class <strong>MockChildComponent</strong> {<br>  getData() { }<br>}</pre><pre>describe(&#39;ParentComponent&#39;, () =&gt; {<br>  let component: ParentComponent;<br>  let fixture: ComponentFixture&lt;ParentComponent&gt;;</pre><pre>  beforeEach(async(() =&gt; {<br>    TestBed.configureTestingModule({<br>      declarations: [<br>        ParentComponent,<br>        <strong>MockChildComponent</strong><br>      ]<br>    }).compileComponents();</pre><pre>fixture = TestBed.createComponent(ParentComponent);<br>    component = fixture.componentInstance;<br>    <strong>component.childComponent = &lt;ChildComponent&gt;TestBed.createComponent(MockChildComponent).componentInstance;</strong><br>    fixture.detectChanges();<br>  }));<br>});</pre><p>Points to note here:</p><ol><li>We’ve created a mock child component here with the same selector name as the original child component. This will resolve the ‘app-child’ unknown element error.</li><li>In the Mock child component definition, we’ll add providers to inject our dependency for the Child component. In <strong>useClass</strong>, we can define the class to be used instead of child component class. This is mostly added for assertions where we check the functions of the child component.</li><li>We’ve added the <strong>getData</strong> function in the mock child component as we’ll be testing it later on. There is no need to add the complete function as the return value of the function is tested in child.component.spec.ts (remember the isolated system of unit testing).</li><li>Don’t forget to add the mock component in the Testbed declarations.</li><li>We’ve defined component.childComponent as an instance of the Mock child component which is of type ChildComponent. Adding the type for the instance as ChildComponent is important over here or we’ll run into an error <em>‘Property ‘ngOnInit’ is missing in type ‘MockChildComponent’ but required in type ‘ChildComponent’’.</em></li></ol><p>Let’s add some assertions now:</p><pre>it(&#39;should check that if showChild in component is false, child component is not displayed&#39;, () =&gt; {<br>  component.showChild = false;<br>  fixture.detectChanges();<br>  const mockComponentEl = fixture.debugElement.query(By.directive(MockChildComponent));<br>  expect(mockComponentEl).toBeNull();<br>});</pre><pre>it(&#39;should check that if showChild in component is true, child component is displayed&#39;, () =&gt; {<br>  component.showChild = true;<br>  fixture.detectChanges();<br>  const mockComponentEl = fixture.debugElement.query(By.directive(MockChildComponent));<br>  expect(mockComponentEl).toBeTruthy();<br>});</pre><pre>it(&#39;should check getData function of child component is called&#39;, () =&gt; {<br>  component.showChild = true;<br>  fixture.detectChanges();<br>  spyOn(component.childComponent, &#39;getData&#39;);<br>  component.ngOnInit();<br>  expect(component.childComponent.getData).toHaveBeenCalled();<br>});</pre><p>Since we’ve added <em>*ngIf</em> on the child component, we’ll assert that when <strong>showChild</strong> is false, the mock child component is null.</p><p>We’ll use <strong>spyOn()</strong> function of Jasmine library to check whether the <strong>getData()</strong> function is triggered when we call ngOnInit() of the parent component. We can also use <strong>toHaveBeenCalledTimes(1)</strong>.</p><p><strong><em>Note:</em></strong><em> Assign value true to showChild before using the spyOn(), otherwise the childComponent will be null as we’ve used *ngIf.</em></p><h3>Service’s dependency in a component or on another Service</h3><p>Services are mostly used for HTTP requests and are then imported in a component to fetch the result. Many time developers create core services which are later used in other services as well. The setup for these services or components are almost similar and thus we’ll look into resolving service dependency in a component here.</p><p><strong>users.component.ts</strong></p><pre>ngOnInit() {<br>  this.userService.getUsers().subscribe(data =&gt; {<br>    this.users = data;<br>  });<br>}</pre><p><strong>user.component.spec.ts</strong></p><pre>import { async, ComponentFixture, TestBed, inject } from &#39;@angular/core/testing&#39;;</pre><pre>import { UserComponent } from &#39;./user.component&#39;;<br>import { of, Observable } from &#39;rxjs&#39;;<br>import { UsersService } from &#39;../users.service&#39;;</pre><pre>class <strong>mockUserService</strong> {<br>  getUsers() : Observable&lt;any&gt; {<br>    const mockData = { &quot;name&quot;: &quot;Gurseerat&quot; }<br>    return of(mockData);<br>  }<br>}</pre><pre>describe(&#39;UserComponent&#39;, () =&gt; {<br>  let component: UserComponent;<br>  let fixture: ComponentFixture&lt;UserComponent&gt;;</pre><pre>  beforeEach(async(() =&gt; {<br>    TestBed.configureTestingModule({<br>      declarations: [ UserComponent ],<br>      <strong>providers</strong>: [{<br>        provide: UsersService,<br>        useClass: <strong>mockUserService</strong><br>      }]<br>    }).compileComponents();<br>    fixture = TestBed.createComponent(UserComponent);<br>    component = fixture.componentInstance;<br>    fixture.detectChanges();<br>  }));</pre><pre>  it(&#39;Service injected via inject(...) and TestBed.get(...) should be the same instance&#39;, <strong>inject([UsersService], (service: UsersService)</strong> =&gt; {<br>    service.getUsers().subscribe(data =&gt; {<br>      expect(<strong>component.users</strong>).toEqual(data);<br>    })<br>  }));<br>});</pre><p>Similar to what we’ve done in resolving dependency in components for child component, we’ve created a <em>mock user service</em> class here which is then added in the TestBed configurations to be injected when user service is called.</p><p>We’re using the <a href="https://angular.io/api/core/testing/inject"><strong>inject()</strong></a> function here for dependency injection of the user service. Alternately, we can also create a TestBed for the service and use it the same way without using the inject() function.</p><p><strong><em>Note:</em></strong><em> The name and type of functions in the mock services should be the same as the original service.</em></p><pre>let userService: UserService;</pre><pre>beforeEach(() =&gt; {<br>  userService = TestBed.get(UserService);<br>});</pre><h3>Windows Property</h3><p>A window property is any data assigned to a window. E.g</p><pre>window[&#39;name&#39;] = &#39;Gurseerat&#39;;</pre><p>If we are using windows properties in the application, we would want to test it too. In this case, we’ll mock our windows data. To do this, we’ll first define windows in app.module.ts, so that it is available globally in the application.</p><p><strong>app.module.ts</strong></p><pre>@NgModule({<br>  declarations: [ ... ],<br>  imports: [ ... ],<br>  providers: [{ <br>    provide: &#39;Window&#39;, <br>    useValue: window <br>  }],<br>})<br>export class AppModule {<br>}</pre><p>Next, add it in the constructor of the component and/or service, where the windows property is being used.</p><p><strong>app.component.ts</strong></p><pre>import { Inject } from &#39;@angular/core&#39;;</pre><pre>constructor( @Inject(&#39;Window&#39;) private window: Window )</pre><p>Now, we’ll create a mock window object in our spec.ts file and use it instead of the actual window property so that our test cases are isolated.</p><p><strong>app.component.spec.ts</strong></p><pre><strong>let mockWindow: Window = &lt;any&gt;</strong>{<br>  name: &quot;Gurseerat&quot;<br>}</pre><pre>beforeEach(async(() =&gt; {<br>  TestBed.configureTestingModule({<br>    declarations: [ AppComponent ],<br>    providers: [{<br>      provide: &#39;Window&#39;,<br>      <strong>useFactory</strong>: (() =&gt; {<br>        <strong>return mockWindow;</strong><br>      })<br>    }]<br>  }).compileComponents();<br>}));</pre><pre>it(&#39;Windows data to be equal to mock window object&#39;, () =&gt; {<br>  expect(window[&#39;name&#39;]).toBe(mockWindow.name)<br>});</pre><p>The <strong>useFactory</strong> field tells the application<strong> </strong>that the provider is a factory function whose implementation is Window. Once we’ve created the mock for the windows data, we can add our assertions.</p><p>This brings us to the end of our series for unit testing in Angular. I’ve tried to cover many important topics here. In case you have any queries, drop a comment. Additionally, you can also find me on <a href="https://www.linkedin.com/in/gurseerat-kaur-885863143/">LinkedIn</a>.</p><p>Happy Coding! 😃</p><h3>References</h3><ol><li><a href="https://angular.io/api">https://angular.io/api</a></li><li><a href="https://codecraft.tv/courses/angular/unit-testing/dependency-injection/">https://codecraft.tv/courses/angular/unit-testing/dependency-injection/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1738be574ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/khojchakra/developers-guide-to-unit-testing-in-angular-part-3-resolving-dependencies-b1738be574ac">Developer’s Guide to Unit Testing in Angular — Part 3 (Resolving Dependencies)</a> was originally published in <a href="https://medium.com/khojchakra">KhojChakra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developer’s Guide to Unit Testing in Angular — Part 2 (Services, Pipes, Directives)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/khojchakra/developers-guide-to-unit-testing-in-angular-part-2-services-pipes-directives-f1045495f98e?source=rss----49a2246aeb46---4"><img src="https://cdn-images-1.medium.com/max/674/1*jBA3e3hHKqOKz06kWLopKw.jpeg" width="674"></a></p><p class="medium-feed-snippet">Explore how to write test cases for shared services, Http services, pipes, and attribute directives in Angular.</p><p class="medium-feed-link"><a href="https://medium.com/khojchakra/developers-guide-to-unit-testing-in-angular-part-2-services-pipes-directives-f1045495f98e?source=rss----49a2246aeb46---4">Continue reading on KhojChakra »</a></p></div>]]></description>
            <link>https://medium.com/khojchakra/developers-guide-to-unit-testing-in-angular-part-2-services-pipes-directives-f1045495f98e?source=rss----49a2246aeb46---4</link>
            <guid isPermaLink="false">https://medium.com/p/f1045495f98e</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[unit-test-tools]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Gurseerat Kaur]]></dc:creator>
            <pubDate>Sat, 15 Aug 2020 18:14:43 GMT</pubDate>
            <atom:updated>2020-09-18T16:38:42.828Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Developer’s guide to Unit Testing in Angular — Part 1]]></title>
            <link>https://medium.com/khojchakra/developers-guide-to-unit-testing-in-angular-part-1-6a5821a80d0a?source=rss----49a2246aeb46---4</link>
            <guid isPermaLink="false">https://medium.com/p/6a5821a80d0a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[jasmine]]></category>
            <category><![CDATA[karma]]></category>
            <dc:creator><![CDATA[Gurseerat Kaur]]></dc:creator>
            <pubDate>Sun, 02 Aug 2020 18:36:19 GMT</pubDate>
            <atom:updated>2022-01-19T08:59:20.363Z</atom:updated>
            <content:encoded><![CDATA[<h3>Developer’s guide to Unit Testing in Angular — Part 1</h3><p><em>Explore how to do unit testing and improve the quality of various pieces of code in Angular using Karma/Jasmine.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*9X5533V0hWbRdSv7Nbnt4g.jpeg" /></figure><h3>What is Unit Testing and why do it?</h3><p>As a new developer, my biggest mistake was not to take unit testing seriously. The educational institutes focus on subjects like algorithms, data structures, and various languages. While these subjects are required for making the apps/software fast and efficient, unit testing is required to make those apps more reliable.</p><blockquote>A unit test, by definition, is testing the smallest <strong>piece of code that can be logically isolated in the system</strong>.</blockquote><p>The purpose is to validate that each piece of code is performing its task well without any external system.</p><blockquote>In Angular, we use Jasmine to write the test cases and then run those test cases in Karma task runner.</blockquote><p>Unit Testing improves the quality of code significantly. It also makes it easier for a developer to add new features by modifying the existing piece of code and not worry much about testing it if the test cases are successful and thus reduce cost and time.</p><h3>Unit Test Setup in Angular</h3><p>While installing <a href="https://cli.angular.io/">Angular CLI</a>, configurations of Karma and Jasmine are automatically installed with it. We’ll find the following configs in <strong>package.json</strong> file under <strong>devDependencies</strong>:</p><pre>&quot;jasmine-core&quot;: &quot;~2.99.1&quot;,<br>&quot;jasmine-spec-reporter&quot;: &quot;~4.2.1&quot;,<br>&quot;karma&quot;: &quot;^4.0.1&quot;,<br>&quot;karma-chrome-launcher&quot;: &quot;~2.2.0&quot;,<br>&quot;karma-coverage-istanbul-reporter&quot;: &quot;^2.1.1&quot;,<br>&quot;karma-jasmine&quot;: &quot;~1.1.1&quot;,<br>&quot;karma-jasmine-html-reporter&quot;: &quot;^0.2.2&quot;</pre><p>To run the test cases, open the terminal and run the command <strong>ng test</strong>. This command will open the default browser window and start running the test cases one by one from <em>spec.ts</em> files in the Angular project.</p><h3>Let’s take an example by testing a Form!</h3><p>Below is a simple HTML snippet for a login form:</p><pre>&lt;form (ngSubmit)=&quot;submitForm()&quot; [formGroup]=&quot;loginForm&quot; novalidate&gt;<br>  &lt;label&gt;Email address&lt;/label&gt;<br>  &lt;input type=&quot;email&quot; placeholder=&quot;Enter email&quot; formControlName=&quot;email&quot;&gt;</pre><pre>  &lt;label&gt;Password&lt;/label&gt;<br>  &lt;input type=&quot;password&quot; placeholder=&quot;Password&quot; formControlName=&quot;password&quot;&gt;</pre><pre>  &lt;input type=&quot;checkbox&quot; class=&quot;form-check-input&quot;  formControlName=&quot;rememberMe&quot;&gt;<br>  &lt;label class=&quot;form-check-label&quot;&gt;Remember Me&lt;/label&gt;</pre><pre>  &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; [disabled]=&quot;!loginForm.valid&quot;&gt;Submit&lt;/button&gt;<br>&lt;/form&gt;</pre><p>Now let’s add the validators in <em>app.component.ts</em> so we can test them later.</p><pre>export class AppComponent {<br>  constructor(private fb: FormBuilder) { }</pre><pre>  loginForm = this.fb.group({<br>    email: [&#39;&#39;, [Validators.required, Validators.email]],<br>    password: [&#39;&#39;, Validators.required],<br>    rememberMe: [false]<br>  });</pre><pre>  formSubmitted = false;</pre><pre>  submitForm() {<br>    this.formSubmitted = true;<br>  }<br>}</pre><p>Now, our form is complete and we are ready to test it. The Angular CLI generates a test file for the <strong>AppComponent</strong> named <strong>app.component.spec.ts</strong>. Let’s first start with setting up all the dependencies and angular testing tools required in our spec.ts file.</p><pre>import { TestBed, async, ComponentFixture } from &#39;@angular/core/testing&#39;;<br>import { AppComponent } from &#39;./app.component&#39;;<br>import { DebugElement } from &#39;@angular/core&#39;;<br>import { By, BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { FormsModule, ReactiveFormsModule } from &#39;@angular/forms&#39;;</pre><pre>describe(&#39;AppComponent&#39;, () =&gt; {<br>  let component: AppComponent;<br>  let fixture: ComponentFixture&lt;AppComponent&gt;;<br>  let de: DebugElement;<br>  let el: HTMLElement;<br>  <br>  beforeEach(async(() =&gt; {<br>    TestBed.configureTestingModule({<br>      declarations: [ AppComponent],<br>      imports: [<br>        FormsModule,<br>        BrowserModule,<br>        ReactiveFormsModule<br>      ]<br>    }).compileComponents();<br>  }));</pre><pre>  beforeEach(() =&gt; {<br>    fixture = TestBed.createComponent(AppComponent);<br>    component = fixture.componentInstance;<br>    de = fixture.debugElement.query(By.css(&quot;form&quot;));<br>    el = de.nativeElement;<br>  })<br>});</pre><p>Let’s go through each item individually to get an idea about why are they used.</p><ol><li><strong>TestBed</strong>: It is the most important Angular testing tool that configures an Angular environment where we can test our components and services.</li><li><strong>async</strong>: We need to define async in beforeEach, so that the asynchronous task is finished first before moving on to another.</li><li><strong>ComponentFixture</strong>: It is a fixture for debugging and testing a component. It contains various methods like detectChanges(), destroy() etc.</li></ol><p>Next, we’ll import various dependencies for this component like <strong>FormsModule </strong>and <strong>ReactiveFormsModule</strong>.</p><p><strong>Note</strong>: We’ll have to import all the dependencies required for a component. In case, the component is dependent on any service or pipe, we’ll have to mock that service or pipe. We’ll come to this in Part 2.</p><p>Now, let us start creating our test cases.</p><pre>it(&#39;should test if submit button is disabled when the form is invalid -- Required fields are empty&#39;, async(() =&gt; {<br>  component.loginForm.controls[&#39;email&#39;].setValue(&#39;&#39;);<br>  component.loginForm.controls[&#39;password&#39;].setValue(&#39;&#39;);<br>  fixture.detectChanges();<br>  expect(el.querySelector(&#39;button&#39;).disabled).toBeTruthy();<br>}));</pre><pre>it(&#39;should test if submit button is disabled when the form is invalid -- Wrong format of email&#39;, async(() =&gt; {<br>  component.loginForm.controls[&#39;email&#39;].setValue(&#39;abc&#39;);<br>  component.loginForm.controls[&#39;password&#39;].setValue(&#39;abc@123&#39;);<br>  fixture.detectChanges();<br>  expect(el.querySelector(&#39;button&#39;).disabled).toBeTruthy;<br>}));</pre><pre>it(&#39;should test if submit button is enabled when the form is valid&#39;, async(() =&gt; {<br>  component.loginForm.controls[&#39;email&#39;].setValue(&#39;abc@abc.com&#39;);<br>  component.loginForm.controls[&#39;password&#39;].setValue(&#39;abc@123&#39;);<br>  fixture.detectChanges();<br>  expect(el.querySelector(&#39;button&#39;).disabled).toBeFalsy;<br>}));</pre><pre>it(&#39;should test if formSubmitted is true&#39;, async(() =&gt; {<br>  component.submitForm();<br>  fixture.detectChanges();<br>  expect(component.formSubmitted).toBeTruthy;<br>}));</pre><pre>it(&#39;should test if submitForm method has been called 0 times&#39;, async(() =&gt; {<br>  fixture.detectChanges();<br>  spyOn(component, &#39;submitForm&#39;);<br>  el.querySelector(&#39;button&#39;).click()<br>  expect(component.submitForm).toHaveBeenCalledTimes(0);<br>}));</pre><p><strong>Some points to note here:</strong></p><ol><li><strong>fixture.detectChanges()</strong> is very important here, otherwise, the testing environment won’t read the values that have been entered and the default values will be an empty string as defined in the component.ts.</li><li>Since we’ve added <strong>Validators.email</strong> as well as a part of the validator for the email field, we can test if the format of the email is valid or not.</li><li><strong>toBeTruthy()</strong> is used if the expect statement returns true and <strong>toBeFalsy()</strong> for a false return.</li><li>In the last test case, we are creating a jasmine spy on the <strong>submitForm</strong> method and then we’ll click the button to submit the form using DOM. We’ll expect that the submitForm method shouldn’t be triggered as the button is disabled because there is no input in the form.</li></ol><p>For the complete app.component.spec.ts file, you can check out this GitHub gist:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6cac9aa71259c5f7c1f1c43d0a2be2d/href">https://medium.com/media/c6cac9aa71259c5f7c1f1c43d0a2be2d/href</a></iframe><h3>References:</h3><ol><li><a href="https://angular.io/guide/testing">https://angular.io/guide/testing</a></li><li><a href="https://jasmine.github.io/">https://jasmine.github.io/</a></li></ol><p><em>To write test cases for services, pipes, and directives, check out the part 2 of this series, </em><a href="https://medium.com/khojchakra/developers-guide-to-unit-testing-in-angular-part-2-services-pipes-directives-f1045495f98e"><em>Developer’s Guide to Unit Testing in Angular — Part 2 (Services, Pipes, Directives)</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a5821a80d0a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/khojchakra/developers-guide-to-unit-testing-in-angular-part-1-6a5821a80d0a">Developer’s guide to Unit Testing in Angular — Part 1</a> was originally published in <a href="https://medium.com/khojchakra">KhojChakra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alternative to :focus-visible pseudo-element using Angular 7]]></title>
            <link>https://medium.com/khojchakra/alternative-to-focus-visible-pseudo-element-using-angular-7-a9a641e297dc?source=rss----49a2246aeb46---4</link>
            <guid isPermaLink="false">https://medium.com/p/a9a641e297dc</guid>
            <category><![CDATA[focus]]></category>
            <category><![CDATA[directives]]></category>
            <category><![CDATA[hostlistener]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular8]]></category>
            <dc:creator><![CDATA[Gurseerat Kaur]]></dc:creator>
            <pubDate>Sun, 26 Jul 2020 15:17:12 GMT</pubDate>
            <atom:updated>2020-07-26T12:10:18.122Z</atom:updated>
            <content:encoded><![CDATA[<h3>An alternative to :focus-visible pseudo-class using Angular 7</h3><p>Keyboard accessibility holds a great significance for websites and web applications for web accessibility. A common bottleneck for front-end developers, sometimes, is the optimized implementation of keyboard accessibility.</p><blockquote>Many users with motor disabilities rely on a keyboard. Blind users also typically use a keyboard for navigation. Some people have tremors which don’t allow for fine muscle control.</blockquote><p>Typically, a user can select a link using <strong>Tab </strong>key and go back to the previous link using <strong>Shift+Tab</strong> keys. There are some native HTML elements that are interactive from keyboard like &lt;<em>a&gt;</em>,<em> &lt;button&gt;</em>,<em> &lt;input&gt;</em>, &lt;<em>select&gt; and </em>&lt;<em>textarea&gt;. </em>Then there are times when the developers have to bind a click event to a &lt;<em>div&gt;, &lt;span&gt;, </em>or any other HTML tag. In such cases, the element is focus-able by adding <strong>tabindex</strong>. (To read more about this, see <a href="https://www.w3.org/TR/wai-aria-practices-1.1/">WAI-ARIA Authoring Practices</a>).</p><p>The first step is adding the design for an element (such as anchor tag or button etc.) which is selected from the keyboard. For this, we use <strong>:focus</strong> pseudo-class. Let&#39;s say, we have a button where we want to add the focused design.</p><pre>button:focus {<br>    outline: none !important;<br>    box-shadow: 0 0 2px 2px #52514f;<br>    -webkit-box-shadow: 0 0 0 2px #52514f;<br>    -moz-box-shadow: 0 0 0 2px #52514f;<br>}</pre><p>On selecting the item with keyboard, it will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*ciYQ8xaUEZo7GfQfhok_KQ.gif" /><figcaption>Elements are selected using keyboard Tab key</figcaption></figure><p>But, uh-oh it will also be focused like this when a user clicks on that button with the mouse and it will stay like that until another element is focused on.</p><p>So, how do we resolve this? One such solution is <strong>:focus-visible </strong>pseudo-element. Unfortunately, this pseudo-element only works on Firefox right now. For the other browsers, developers use various hacks but all hacks have their limitations.</p><h3>Let&#39;s find a Solution!</h3><p>To resolve this, I found a simple solution in Angular using directives. You just need to create a directive and add an event listener for the <strong>mousedown</strong> event on your element using <strong>@hostlistener</strong> decorator. Hostlistener declares a DOM event to listen for and provides a handler method to run when that event occurs.</p><p>But what do we do in this directive? Whenever there is a <strong>mousedown</strong> event, we will simply add a class <strong><em>focus-hide</em></strong><em> </em>to that element. The mousedown event occurs when the left mouse button is pressed down over the selected element.</p><pre>@Directive({<br>  selector: &#39;[focusHide]&#39;<br>})</pre><pre>export class FocusHideDirective {</pre><pre>@HostListener(&quot;mousedown&quot;, [&quot;$event&quot;])<br>public onMouseDownTrigger(event: any) {<br>   event.srcElement.classList.add(&quot;focus-hide&quot;)<br>}</pre><p>Next, we will add a CSS design to <em>.focus-hide</em> class and unset all our focus designs.</p><pre>button:focus {<br>    outline: none !important;<br>    box-shadow: 0 0 2px 2px #52514f;<br>    -webkit-box-shadow: 0 0 0 2px #52514f;<br>    -moz-box-shadow: 0 0 0 2px #52514f;</pre><pre>&amp;.focus-hide {<br>       box-shadow: none !important;<br>    }<br>}</pre><p>Next, add your directive in your HTML tag like this:</p><pre>&lt;button class=&quot;btn&quot; focusHide&gt;Button&lt;/button&gt;</pre><figure><img alt="Could it really be that simple?" src="https://cdn-images-1.medium.com/max/705/1*ZOrNWTP-Hi4ECbr3XbfrqA.jpeg" /><figcaption>Could it really be that simple?</figcaption></figure><p>NO! What if the user wants to select that element with the keyboard now? Many users use both keyboard and mouse to go through a web page. We will create another @hostlistener for <strong>focusout</strong> event and remove the class <em>focus-hide (and voila!). </em>The focusout event is fired when an element is about to lose focus.</p><pre>@HostListener(“focusout”, [“$event”])<br>public onFocusOutTrigger(event: any): void {<br>   event.srcElement.classList.remove(“focus-hide”)<br>}</pre><p>For the complete example, you can check it out on the GitHub here,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/457313b43a6ecc90a2cedbe09768d23f/href">https://medium.com/media/457313b43a6ecc90a2cedbe09768d23f/href</a></iframe><p>Thank you for reading my first post on Medium 😃 Don’t forget to give a clap!</p><h4>Reference</h4><ol><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible">https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible</a></li><li><a href="https://angular.io/guide/attribute-directives">https://angular.io/guide/attribute-directives</a></li><li><a href="https://angular.io/api/core/HostListener">https://angular.io/api/core/HostListener</a></li><li><a href="https://www.w3.org/TR/wai-aria-practices-1.1/#kbd_general_between">https://www.w3.org/TR/wai-aria-practices-1.1</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9a641e297dc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/khojchakra/alternative-to-focus-visible-pseudo-element-using-angular-7-a9a641e297dc">Alternative to :focus-visible pseudo-element using Angular 7</a> was originally published in <a href="https://medium.com/khojchakra">KhojChakra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I have designed an attractive radio button with simple HTML and CSS only]]></title>
            <link>https://medium.com/khojchakra/how-i-have-designed-an-attractive-radio-button-with-simple-html-and-css-only-efafa2f742d7?source=rss----49a2246aeb46---4</link>
            <guid isPermaLink="false">https://medium.com/p/efafa2f742d7</guid>
            <dc:creator><![CDATA[Saurabh Kumar]]></dc:creator>
            <pubDate>Fri, 08 May 2020 03:21:56 GMT</pubDate>
            <atom:updated>2020-05-08T13:57:23.895Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*uO61_ZIFV2Se7B4kqWpl2A.jpeg" /><figcaption>source: google</figcaption></figure><p>For any web or mobile application, whether it is a minimum viable product (MVP) or fully functional production ready application irrespective of business model, in my opinion, user interface (UI)/user experience (UX) is the first and most important thing people notice once they landed on your application. don’t you think so..?? well, personally I also notice UI/UX first whenever I open any application online.</p><h3>Why UX is so important for us?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*k3MpWkb_m83NCGiCqhe2tA.jpeg" /><figcaption>source: google</figcaption></figure><p>I believe UX plays a vital role in the success of any application. It increases user&#39;s engagement to your application and hence customer satisfaction and more hits to your website or application. a win-win for both I guess... 😛</p><p>people almost never come back to application or website having bad UI/UX, unless their competitor has even more bad UX.. 😝 just kidding..!! people always think from their own perspective whether the application is easy and nice to use for them.</p><p>I personally feel UI/UX increases product value...!! if you don’t feel the same, well then I will not argue with you as you are also correct from your perspective.</p><p>So I was thinking to create some nice user experience out of boring default form elements that are available in HTML5 by default. My goal was to provide a rich and interactive experience for the users who uses the application and feel great about it.</p><p>I started experimenting with different approaches for designing the radio button which should be simple yet with a nice user experience. so here I am sharing one of the radio button code with you all.</p><p>I will try to explain what I have done here as simple as possible, I change the look of radio button by making it bigger in size and ensure that the transition of switching from one option to another have a feel like a little push and pull and gravitation do the rest of the work. that&#39;s it..!!!</p><p>below are the CSS file and the simple HTML5 form for designing the radio button</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f50d0d08e708e54c1ef32ed9fed55475/href">https://medium.com/media/f50d0d08e708e54c1ef32ed9fed55475/href</a></iframe><p>and here is the result from the above 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*CVHKfR1GzEYCgRuz0sx-Jw.gif" /></figure><p>here you can observe how few lines of CSS impacted the UI/UX</p><h3>About the author</h3><p><a href="https://sk-cse.github.io/">Saurabh Kumar</a></p><p>feel free to follow me on GitHub <a href="https://github.com/SK-CSE">https://github.com/SK-CSE</a></p><p>or connect with me on LinkedIn <a href="https://www.linkedin.com/in/saurabh-kumar-7748015a/">https://www.linkedin.com/in/saurabh-kumar-7748015a/</a></p><p>for more post like this follow <a href="https://medium.com/khojchakra">https://medium.com/khojchakra</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efafa2f742d7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/khojchakra/how-i-have-designed-an-attractive-radio-button-with-simple-html-and-css-only-efafa2f742d7">How I have designed an attractive radio button with simple HTML and CSS only</a> was originally published in <a href="https://medium.com/khojchakra">KhojChakra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Steps for Appium Installation in Ubuntu]]></title>
            <link>https://medium.com/khojchakra/steps-for-appium-installation-in-ubuntu-16ea659cd145?source=rss----49a2246aeb46---4</link>
            <guid isPermaLink="false">https://medium.com/p/16ea659cd145</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[installation]]></category>
            <category><![CDATA[appium]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Awaneesh  Singh]]></dc:creator>
            <pubDate>Thu, 07 May 2020 12:22:45 GMT</pubDate>
            <atom:updated>2020-05-07T12:51:05.696Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3LEMkgStgOhX1kSi08oZhQ.jpeg" /><figcaption>Image source:Unslpash.com</figcaption></figure><p>What is <strong>Appium</strong>?</p><p><strong>Appium</strong> is an open-source tool for automating native, mobile web, and hybrid applications on iOS mobile, Android mobile, and Windows desktop platforms. A cross-platform allows you to write tests against multiple platforms i.e., iOS, Android, Windows using the same API. This enables code reuse between iOS, Android, and Windows test-suites.</p><p>If in case you are new to this Appium world than let us start the journey with some easiest step of installation that ll help you covering half of the journey to Appium.</p><p>Here is a list of prerequisite which we need to have in our machine before jumping into in installation steps:</p><ol><li>Download Java and set Java Home in the environment variable</li><li>Download Android Studio and set up Virtual Device</li><li>Download Nodejs and npm</li></ol><p>Let us look into the above prerequisites one by one.</p><p><strong>Java installation and setup</strong></p><p>Let us check if we have java installed in our machine or not to do so hit the below command in your terminal.</p><pre>$ java --version</pre><p>If you have java installed in your machine you will have output as shown below with the respective version, I have java 11 as my version same can be seen in the below snapshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*xiTWRh8JhpYUvXdoC0grww.png" /></figure><p>Now that we have verified that our system has Java let us verify the JAVA_HOME path and for doing this hit the below command</p><pre>$ echo $JAVA_HOME</pre><p>this ll return you the path for the same below is what I have got after running the command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*MimZufLE4r2a18wVTnKGQQ.png" /></figure><p>If in case you were not able to find the response for any of the above command please click on the below link to get set up done for java in your machine</p><p><a href="https://medium.com/khojchakra/how-to-install-and-setup-java-in-ubuntu-b88fe625f94f">How to install and setup JAVA in Ubuntu</a></p><p>Now that you are reading this line that means Java has been installed in your machine.one milestone achieved let us move to the next one.</p><p><strong>Download Android Studio and set up virtual Device</strong></p><p>Android Studio is the official integrated development environment for Google’s Android operating system, built on JetBrains’ IntelliJ IDEA software and designed specifically for Android development. In our case we can also use the virtual devices available in the android studio to run our automated test cases.</p><p>let us see the installation step of Android studio, you need to install android studio in your system click on the below link</p><p><a href="https://developer.android.com/studio">https://developer.android.com/studio</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B32-E4uyqV5O3wCK0kmcyg.jpeg" /></figure><p>The next step is to just install the downloaded file. once installed let us launch the next click on the Tools → SDK manager your screen will be as the below one</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ajEScuJr7LWOgtsHg54XMA.jpeg" /></figure><p>Check the Android SDK Tools checkbox and get it installed by clicking on Apply</p><p>Now let us see how to set up a virtual device in Android studio. In the menu bar click on Tools and the AVD Manager below screen will pop up after the click</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VOWpyq7G-de5CG-S59TeIQ.png" /></figure><p>Click on the + create virtual Device and select one of the virtual devices available on the list and complete the configuration part for the device. the one you have created ll be listed in the above screen list of your virtual devices.</p><p>Let us launch the virtual device that we created to do so follow the below step</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kBGpZ-6Ae7en9INU0ctz7Q.jpeg" /></figure><p>soon after the click AVD will launch the virtual device as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*WkhZ41SGsaEfJ0cHOpWKrA.png" /></figure><p>Cheers we have moved one more step closer to Appium installation.</p><p><strong>Download Nodejs and npm</strong></p><p>Node.js is a JavaScript platform for general-purpose programming that allows users to build network applications quickly. Let us use below command to install Node.js and npm respectively</p><pre>$ sudo apt-get install nodejs</pre><pre>$ sudo apt-get install npm</pre><p>Now that we have successfully installed all the prerequisite let us move to the installation step for Appium</p><p><strong>Appium Installation</strong></p><p>Let us type the below command to start with Appium installation in your machine</p><pre>$ sudo npm install -g appium</pre><p>As soon as you hit the above command it will prompt for your system password to enter, provide the same, and wait for the installation process to get completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*576jxhheR1x8qyGrDm7bBQ.png" /></figure><p>cheers !!!!!</p><p>Appium is installed in your system, Now let us use the below command in terminal to start the Appium server</p><pre>$ appium</pre><p>and you will have the below screen that you have been waiting for this is the place where you ‘ll have all logs shown up</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*UF4VFVg__8XUdAqH3vELcQ.png" /></figure><p>Congratulations on successfully installing Appium in your machine. Your machine is now ready for mobile automation. Stay connected for more information on Appium Automation.</p><h3>About the Author</h3><p>I’m aTest Automation engineer trying to be a helping hand.</p><p>Connect with me on LinkedIn <a href="https://www.linkedin.com/in/awaneesh-singh-9033b944/">https://www.linkedin.com/in/awaneesh-singh-9033b944/</a></p><p>for more post like this follow us: <a href="https://medium.com/khojchakra">https://medium.com/khojchakra</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16ea659cd145" width="1" height="1" alt=""><hr><p><a href="https://medium.com/khojchakra/steps-for-appium-installation-in-ubuntu-16ea659cd145">Steps for Appium Installation in Ubuntu</a> was originally published in <a href="https://medium.com/khojchakra">KhojChakra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to install and setup JAVA in Ubuntu]]></title>
            <link>https://medium.com/khojchakra/how-to-install-and-setup-java-in-ubuntu-b88fe625f94f?source=rss----49a2246aeb46---4</link>
            <guid isPermaLink="false">https://medium.com/p/b88fe625f94f</guid>
            <category><![CDATA[installation]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[appium]]></category>
            <dc:creator><![CDATA[Awaneesh  Singh]]></dc:creator>
            <pubDate>Wed, 06 May 2020 17:28:34 GMT</pubDate>
            <atom:updated>2020-05-06T17:30:35.932Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to install and setup JAVA in Ubuntu 💻</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eA2m1i42bH2TpjTg6aiZAQ.jpeg" /><figcaption>image source: google</figcaption></figure><p>Java is a general-purpose programming language that is class-based, object-oriented, and designed to have as few implementation dependencies as possible.</p><p>let us have a look into the installation process and setting up environment variables</p><p>Installation Steps:</p><p>First, make sure that you have updated apt package for doing so type the below command in your terminal</p><pre>$ sudo apt update</pre><p>After hitting with the above command it ll ask you for your systems password do enter that and wait for the packages to get updated.</p><p>Now that our package index is updated let us move to the next step of installing default JDK by hitting the below command</p><pre>$ sudo apt install default-jdk</pre><p>Now let us verify the installation in your machine with the help of below command</p><pre>$ java --version</pre><p>Above command, ll return you the version of java installed in your machine, here is the sample snapshot of the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*xiTWRh8JhpYUvXdoC0grww.png" /></figure><p>Now that you are here I hope you have java installed in your machine.</p><p>Steps to set JAVA_HOME path</p><p>Now that we have Java installed to our machine, let us proceed to set up JAVA_HOME path for this we need to have the exact location of JDK installed for Ubuntu machine the path is /usr/ lib/jvm/java-11-openjdk-amd64</p><pre>$ gedit .bashrc</pre><p>type the above command in your terminal this ll open a file in text view in that file at the bottom add the below line</p><pre>export JAVA_HOME=&quot;/usr/lib/jvm/java-11-openjdk-amd64&quot;<br>export PATH=$JAVA_HOME/bin:$PATH</pre><p>once added save the file and close it. Now let us verify if the path is set in your system or not by hitting the below command in your terminal.</p><pre>echo $JAVA_HOME</pre><p>you ll have the below response</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*kvxDtxSTjqqmfyhhILdytA.png" /></figure><p>Now that you are done with set up in your machine, it is ready to run java based application.</p><p>Happy coding cheers!!!!!</p><h3>About the Author</h3><p>I’m aTest Automation engineer trying to be the hope of light.</p><p>Connect with me on LinkedIn <a href="https://www.linkedin.com/in/awaneesh-singh-9033b944/">https://www.linkedin.com/in/awaneesh-singh-9033b944/</a></p><p>for more post like this follow us: <a href="https://medium.com/khojchakra">https://medium.com/khojchakra</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b88fe625f94f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/khojchakra/how-to-install-and-setup-java-in-ubuntu-b88fe625f94f">How to install and setup JAVA in Ubuntu</a> was originally published in <a href="https://medium.com/khojchakra">KhojChakra</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>