<?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 Bradley on Medium]]></title>
        <description><![CDATA[Stories by Bradley on Medium]]></description>
        <link>https://medium.com/@mashaobradley?source=rss-bf918357ff33------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bI_ribbhuNCeVox_z7q6qw.png</url>
            <title>Stories by Bradley on Medium</title>
            <link>https://medium.com/@mashaobradley?source=rss-bf918357ff33------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 03:19:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mashaobradley/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[Angular Http Interceptors: An Overview]]></title>
            <link>https://medium.com/dvt-engineering/angular-http-interceptors-an-overview-f87aa14f0c10?source=rss-bf918357ff33------2</link>
            <guid isPermaLink="false">https://medium.com/p/f87aa14f0c10</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[dvt]]></category>
            <category><![CDATA[interceptors]]></category>
            <dc:creator><![CDATA[Bradley]]></dc:creator>
            <pubDate>Sun, 06 Nov 2022 22:55:44 GMT</pubDate>
            <atom:updated>2022-12-01T10:33:26.585Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Angular HTTP Interceptors: An Overview</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PPLl6Yj13aDMbjkd.png" /><figcaption>Angular interceptor basic architecture</figcaption></figure><p><strong>What, in simple terms, is an HTTP interceptor?</strong></p><p>Let’s start by defining an interceptor and examining the justification for its necessity.</p><p>Angular’s official website provides the following description of HTTP interceptor.</p><blockquote><em>“Intercepts and handles an HttpRequest or HttpResponse”</em></blockquote><p>Simply put, the interceptor adds a step before our HTTP requests are sent or before the result returns or leaves our Angular application.</p><p>Angular interceptors are one of the most important parts of Angular. As shown above, they create a proxy between the server and the client. This proxy can be used for:</p><ul><li><strong>authentication</strong>,</li><li><strong>authorization</strong>,</li><li><strong>caching, and much more.</strong></li></ul><p>The main purpose of an Angular interceptor is to modify <em>requests</em> or responses before they hit their<em> target</em>.</p><p><em>🙃Pheeeeuw, that was a mouthful!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*_kGbWlQDGTQMRrUW" /></figure><p>But I’ve finally intercepted your interest in Angular interceptors.</p><p><strong>Use cases for HTTP interceptors</strong></p><ul><li>For our outgoing queries, include a token or customized HTTP header.</li><li>Before transferring the data to your service or component, catch HTTP responses to perform some logic.</li><li>Verify the user’s authentication.</li><li>Correct mistakes.</li><li>Both loaders and notifications.</li></ul><p><em>There is more to it.</em></p><p>We’ll discuss angular HTTP interceptors in detail. To put one in your project, follow the instructions in this step-by-step guide.</p><p>We will focus on the most typical use case and add a token to HTTP headers before our requests are sent out from our application. Now that we understand what an HTTP interceptor is let’s develop a basic one.</p><h4>Step 1: Create a new Angular project</h4><p>We first need to start a new Angular project using the command below.</p><blockquote>ng new http-intercept-demo</blockquote><h4>Step 2: Create an Interceptor</h4><p>Create an interceptor using the following command.</p><blockquote>ng g interceptor authentication</blockquote><h4>Step 3: Creating a service is the third step</h4><p>ng g service http</p><p>By following these commands, a new Angular app with the following two files will be created:</p><ul><li><em>auth.interceptor file.</em></li><li><em>http.service file(Regular service).</em></li></ul><p>Now that our files have some code let’s add a get function to the HTTP service that will send an HTTP request to the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kYMquyZBHt_8DG0w4TUSxA.png" /><figcaption>http.service file</figcaption></figure><p>Now, in the auth.interceptor file, implement the intercept method.</p><p>Every outgoing request will have the intercept method function run.</p><p>Two parameters of the types HttpRequest and HttpHandler are passed to the function.</p><p>In our example, “requestToHandle” stands for the outgoing request object we want to manage, and “next” stands for the next interceptor in the chain, or the backend if none are left.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a8rdyD4l-u5kKCMFdAbBcA.png" /><figcaption><em>auth.interceptor file</em></figcaption></figure><p>After making this alteration, we must update the providers array in the app.module and inform Angular to use the newly generated interceptor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L0wnfq3pncozCyuc-ze7Jw.png" /></figure><p>This can be done in the providers.</p><p>The next step is to build a straightforward template with a button in app.component that will activate the get function in our service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*On7l7Lw43RU5Skkx-vNheg.png" /></figure><p>We’re done, so go ahead and check out your new interceptor. Every outgoing request will now automatically add a token header and call the intercept method.</p><p>You may check it in the browser by clicking on the request you issued in the Chrome Developer Tools network tab.</p><p>In conclusion, HTTP interceptors are a very effective tool that enables us to modify HTTP requests and add any necessary logic before they are sent to or received by our Angular application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f87aa14f0c10" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dvt-engineering/angular-http-interceptors-an-overview-f87aa14f0c10">Angular Http Interceptors: An Overview</a> was originally published in <a href="https://medium.com/dvt-engineering">DVT Software Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Test-Driven JavaScript Development with Cypress — The Complete Guide]]></title>
            <link>https://medium.com/dvt-engineering/test-driven-javascript-development-with-cypress-the-complete-guide-ba18016cab39?source=rss-bf918357ff33------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba18016cab39</guid>
            <category><![CDATA[cypress-testing]]></category>
            <category><![CDATA[angular-testing]]></category>
            <category><![CDATA[test-drive-development]]></category>
            <category><![CDATA[unitt-testing]]></category>
            <dc:creator><![CDATA[Bradley]]></dc:creator>
            <pubDate>Fri, 04 Nov 2022 22:32:16 GMT</pubDate>
            <atom:updated>2022-11-14T13:45:49.570Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Test-Driven JavaScript Development with Cypress — The Complete Guide</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0c3ZnCtzTw1xq6YS.jpg" /></figure><p>There are many unit testing frameworks in JavaScript, but it can be difficult to choose one. A lot of them have overlapping features and similar syntax. Some even have a steep learning curve. Thankfully, the Cypress framework is here to save the day! It’s a modern and easy-to-use unit testing framework that allows you to write tests with a more human-friendly syntax. This article will cover the how and why questions regarding the cypress automation testing tool.</p><p>Cypress is a JavaScript testing framework that you can use in your development process as an extension of test-driven development. It provides a browser-based interface for managing, running and debugging your tests. Cypress has been created to solve the challenge of manual testing with today’s frameworks and libraries.</p><h3><strong>What is Test-driven development:</strong></h3><p>Test-driven development is a process for software development. It’s an iterative and incremental approach to software design, which relies heavily on testing. Software projects must pass a series of tests before the final product can be shipped.</p><p><strong>Is it Free or not?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*ZNErnReylurF47dX.jpg" /></figure><p>Cypress is an open-source, cross-platform test runner.</p><p>With a single click, it lets you execute tests written with any testing framework or language on any OS.</p><p><strong>It Runs itself:</strong></p><p>Cypress runs itself in a Chrome browser, making it easy to debug tests as they’re executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*C4ARuCW9XeO_RrVM.jpg" /></figure><h3><strong>How to use Cypress the professional way:</strong></h3><p>If you are a professional (i assume you are 🤓) or someone who has just started in the field of software testing, then you know that there are certain tools which are must-haves and Cypress is one of them. In this article, we will look at how Cypress can help you work efficiently and better as a professional.</p><p>To explain it more simply, the tool provides seamless integration with other tools and allows testers to save loads of time. Here are some benefits of using the tool:</p><ol><li>Test code is written in JavaScript (no need for any programming language knowledge) by using an interactive prompt interface. It saves time and effort, which otherwise would have gone into learning basic.</li><li>It captures snapshots at the time of test execution. This allows QAs or developers to hover over a specific command in the Command Log to see exactly what happened at that particular step.</li><li>Developers can use Spies, Stubs, and Clocks to verify and control the behaviour of server responses, functions, or timers.</li><li>As the programmer writes commands, Cypress executes them in real time, providing visual feedback as they run.</li><li>Cypress overall carries excellent documentation.</li></ol><h3><strong>How to setup/Install Cypress</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FJjNzet8860koZpHCsyaJQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HhOkZysDd9lAfkJy2tB50Q.png" /></figure><h3><strong>How to set up a Cypress project</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6g_MSyHMe_Q3pbSSYNgi0Q.png" /></figure><p>We will then name our first spec file,<em>test.spec.js. </em>And below, we will add our first passing test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YPkYqt5g5EoW7n728npYLQ.png" /></figure><p>Once the Cypress test runner reloads, our test body will show the name of the test, “Does not do much!” and the test body highlighted in green text to signify a passing test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KwRJUMU-Ul26CJDVdVfNNA.png" /></figure><h3>Important points to remember: <em>A solid test generally covers 3 phases</em></h3><ol><li>Set up the application state</li><li>Take an action</li><li>Make an assertion about the resulting application state</li></ol><p>To further explain the steps above, we’ll narrowly view these steps and map them cleanly to Cypress commands.</p><p>To explain this in further detail, say you’re writing a test to visit a specific URL and want to find an element by its content; how would you go about doing this? Here’s how:</p><h4>Step 1: Visit a page (this will be the first step above)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NaO31sdlBvRcKFX7qf02pQ.png" /><figcaption>Here we visit example.cypress.io</figcaption></figure><h4>Step 2: Query for an element</h4><p>we, therefore, query the element in the link we visited for a specific content</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HrPyQU5zkYL9dibakNryRQ.png" /></figure><h4>Step 3: Click an element</h4><p>Now let us click the element which contains content “type”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*APT9e3S5Gucyinwt2WfYIw.png" /></figure><h4>Step 4: Make an assertion</h4><p>Here we then assert if the URL shown after clicking the element is the correct expected URL using the cypress command <em>should, include</em> for example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E5uuegr66ELHhqLq_sNm0g.png" /></figure><p>As you can see, Cypress is a powerful and crucial tool in the testing architecture for testers and developers. I hope this article piqued your interest enough for you to do more complex tests in your application to ensure everything is running exactly as expected. Happy testing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba18016cab39" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dvt-engineering/test-driven-javascript-development-with-cypress-the-complete-guide-ba18016cab39">Test-Driven JavaScript Development with Cypress — The Complete Guide</a> was originally published in <a href="https://medium.com/dvt-engineering">DVT Software Engineering</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 detect changes on an @Input with Angular.]]></title>
            <link>https://medium.com/dvt-engineering/how-to-detect-changes-on-an-input-with-angular-a3dd5f1caf7f?source=rss-bf918357ff33------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3dd5f1caf7f</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[input-output]]></category>
            <dc:creator><![CDATA[Bradley]]></dc:creator>
            <pubDate>Mon, 22 Aug 2022 22:06:06 GMT</pubDate>
            <atom:updated>2022-10-21T12:06:00.068Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most frustrating things you’ll encounter when writing Angular code is how to trickle down (pass down information rather) from the parent component down to the child component that you re-use in various components.</p><p>Well, that’s the problem I found myself in the first few weeks of working with Angular. From my previous React/React Native background, this was such an easy thing to do. It was a shocking surprise when I read a little more into the workings of “the how to” achieve this in angular.</p><p>Essentially, the solution boils down to two approaches:</p><ol><li>The easier route (Letting Angular do the work for you) and</li><li>The more “in control” approach where you define a single getter and setter on an input property. Not only can we use getters and setters to achieve this, but we can define a private property and use getters and setters on them, using getters to retrieve these properties (say to display them in a view).</li></ol><h3>Step 1: The Easy approach</h3><p>Here’s how we can write a component to use <em>ngOnchanges </em>to detect changes on an input.</p><p>Let’s say you’re a huge music fanatic. You live and breathe music and want to detect and log changes when there’s a music change in your player component; how do you go about this? Well, hook to the lifecycle — use one of <em>Angular’s lifecycle hooks.</em></p><p><em>ngOnChanges()</em> is one of the many angular lifecycle hook methods. This one, in particular, responds when a data-bound input property has a change invoked. This method receives SimpleChanges object.</p><p>SimpleChanges object consists of current and previous property values, which we can use to check if any changes have been detected by our @Input decorator.</p><p>Let’s see how we can listen to changes on an Input using this lifecycle method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2wYqVlbCgIBBleqo8zmzIg.png" /><figcaption>SelectedMusicPlayerComponent.component.ts</figcaption></figure><p>Here we have a player <em>@Input</em> of type Player. On line 7, we check if player firstChange is false, that is, if the player input has received a change. If that is the case, then proceed to log the currentValue or new recently updated player data. This is achieved by using the changes object, which contains the <em>current</em> and <em>previous</em> values of <em>player.</em></p><h3>Step 2 : Self-defined approach: Setters and Getters</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*AINNo56kw6JSvMHTWBUYMQ.png" /></figure><p>Here our <em>SelectedMusicPlayerComponent</em> has an <a href="http://twitter.com/Input">@Input</a> decorator. We set a setter “player” function to this Input decorator to detect changes to the player function; essentially, whenever the player property changes, the set will be called. And we’re done! Or, are we? No, we’re not.</p><p>This set on its own cannot work. It only allows us to display the detected change on the console, or in this case, “value” logged. So to display the property onto our template (myComponent.html), we need to define a private property.</p><h3>Private Property and getter</h3><p>We can define a private property to hide or display the detected change onto our template HTML when needed like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2mpC-55UfayvsbPyBK_dWA.png" /></figure><p>Above, we introduced a <em>get. </em>This essentially gets the data and returns it, unlike a set that allows us to initialise our property, in this case, our “_selectedPlayer” to a detected change (value).</p><p>Fun fact for the <em>fun code</em> lovers. <em>set</em> will always be invoked first before <em>ngOnchanges</em> lifecycle hook because it is plain typescript/javascript.</p><p>I hope this short post has at least piqued your interest in exploring the many different ways we could listen to change bound to an input decorator and proceed with writing amazing code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3dd5f1caf7f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dvt-engineering/how-to-detect-changes-on-an-input-with-angular-a3dd5f1caf7f">How to detect changes on an @Input with Angular.</a> was originally published in <a href="https://medium.com/dvt-engineering">DVT Software Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>