<?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 Fagner Araujo on Medium]]></title>
        <description><![CDATA[Stories by Fagner Araujo on Medium]]></description>
        <link>https://medium.com/@fagnersaraujo?source=rss-a37cf1e739b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*qgPfOXLSzSo7qYV_.jpeg</url>
            <title>Stories by Fagner Araujo on Medium</title>
            <link>https://medium.com/@fagnersaraujo?source=rss-a37cf1e739b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 07:52:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fagnersaraujo/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[Mocking read-only imports with Vitest]]></title>
            <link>https://medium.com/@fagnersaraujo/mocking-read-only-imports-with-vitest-35449bd9aadd?source=rss-a37cf1e739b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/35449bd9aadd</guid>
            <dc:creator><![CDATA[Fagner Araujo]]></dc:creator>
            <pubDate>Fri, 16 Feb 2024 16:16:31 GMT</pubDate>
            <atom:updated>2024-02-16T16:16:31.026Z</atom:updated>
            <content:encoded><![CDATA[<p>Part of the unit test is to check if some method was called but sometimes, it&#39;s inside an import flagged with read-only.</p><p>In this example, I am using the AWS Amplify library to log in.</p><p>So, I need to call the method signInWithRedirect() presented inside the domain auth and it&#39;s read-only.</p><p>Every time I do a spy an error occurs warning that the property is read-only of an Object Module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*b0RXRyno2e6DmM_iogigAA.png" /></figure><p>To make it work, we need to mock the library and set the esModule to true which will allow us to rewrite the method.</p><pre>import * as AmplifyAuth from &#39;aws-amplify/auth&#39;<br>vi.mock(&#39;aws-amplify/auth&#39;, () =&gt; ({<br>  __esModule: true,<br>  signInWithRedirect: vi.fn()<br>}))</pre><p>And now we can spy our method to make the check</p><pre>beforeEach(() =&gt; {<br>  spySignInWithRedirect = vi.spyOn(AmplifyAuth, &#39;signInWithRedirect&#39;)<br>})</pre><p>Finally, the test can be done</p><pre>test(&#39;should call SignIn function&#39;, async () =&gt; {<br>  ...<br>  expect(spySignInWithRedirect).toHaveBeenCalled()<br>})</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35449bd9aadd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Breadcrumbs automatizado com VueJS]]></title>
            <link>https://medium.com/@fagnersaraujo/breadcrumbs-automatizado-com-vuejs-8c06781d0320?source=rss-a37cf1e739b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c06781d0320</guid>
            <category><![CDATA[vue-router]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[breadcrumbs]]></category>
            <category><![CDATA[single-page-applications]]></category>
            <dc:creator><![CDATA[Fagner Araujo]]></dc:creator>
            <pubDate>Mon, 12 Mar 2018 01:17:49 GMT</pubDate>
            <atom:updated>2018-03-12T01:17:49.375Z</atom:updated>
            <content:encoded><![CDATA[<p>Você precisa colocar um breadcrumb no seu site ou aplicação e está pensando em adicionar uma biblioteca pra isso? Que tal entender o que é e como funciona antes? então, é sobre isso que trataremos aqui.</p><h3>O que é?</h3><blockquote>“Breadcrumb é um meio de navegação dentro de uma aplicação que permite ao espectador saber exatamente onde ele está.“</blockquote><p>Com isso, ele pode voltar a uma etapa anterior ou até mesmo alinhar melhor seu entendimento da aplicação.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*4sujZH8UsNg5r5NsDAn6ng.png" /><figcaption>Breadcrumb no site da BBC.</figcaption></figure><p><em>Observando o site da BBC você percebe que o assunto é </em><strong><em>England</em></strong><em> e a matéria está dentro da seção </em><strong><em>London</em></strong><em> que pertence a </em><strong><em>Local News</em></strong><em> e </em><strong><em>Regions</em></strong><em>.</em></p><h3>O que vamos utilizar?</h3><p>Como o framework principal utilizaremos o VueJS. Se ainda não utilizou, <a href="https://vuejs.org/v2/guide/">dê uma olhada no site oficial e se encante com ele!</a></p><p>Para as rotas utilizaremos o plugin oficial do Vue chamado <strong>Vue-Router</strong>. Você pode conhecê-lo com mais detalhes <a href="https://router.vuejs.org/en/">aqui</a></p><h3>Iniciando um projeto do zero</h3><blockquote>Nessa etapa iremos criar um projeto do zero utilizando o <a href="https://github.com/vuejs/vue-cli"><strong>vue-cli</strong></a>. Caso seu projeto já tenha sido criado, vá para a próxima etapa — Preparando o terreno.</blockquote><p>O vue-cli é um biblioteca global que pode ser instalada com o comando:</p><pre>npm install --global vue-cli</pre><p>Para criar um projeto pré-configurado com webpack e tudo mais, rode:</p><pre>vue init webpack breadcrumbs</pre><p>Serão feitos algumas perguntas básicas. Basta responder atentando-se a dizer <em>yes</em> ao vue-router. Abaixo segue a configuração que eu utilizei.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*_yoJCe6wrd1bEp6u7x8iQw.png" /><figcaption>Configuração utilizada nesse exemplo.</figcaption></figure><p>Com essa etapa concluída você já terá uma estrutura de pastas pronta e seu primeiro componente criado, além de sua primeira rota já criada.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*A2TI2CuwMX1e7l1TAFA-cQ.png" /><figcaption>Estrutura de pastas com o primeiro componente e a rota apontando para ele.</figcaption></figure><h3>O básico do vue-router</h3><p>Em um SPA é fundamental uma engine que trate as rotas. no VueJS o <em>vue-router</em> é a engine oficial.</p><p>Uma rota básica é composta por <strong>path</strong>, <strong>name</strong> e <strong>component. </strong>Onde <strong>path</strong> guarda o caminho da URL a ser roteada, <strong>name</strong> define como poderemos chamar essa rota e <strong>component</strong> aponta para qual componente a rota irá renderizar.</p><p>Adicionaremos uma chave chamada <strong>meta</strong> que será o responsável pela automatização do nosso breadcrumb. Veremos isso mais a frente.</p><h3>Preparando o terreno</h3><p>Vamos começar criando quatro novos componentes que se ligarão através de links.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*r4DcVRcuG2qvCM3Xgdu2WQ.png" /><figcaption>Os arquivos que usaremos.</figcaption></figure><p>A estrutura que defini para a hierarquia é:</p><pre>Area 1<br>  Area 1 - 2<br>    Area 1 - 2 - 1<br>Area 2</pre><p>Bem simples: <em>Area 1 — 2 — 1</em> está contido em <em>Area 1 — 2</em> que por sua vez está contido na <em>Area 1</em>.</p><p>As áreas apontam para outras áreas utilizando o <em>router-link</em>. O <em>router-link</em> é um dos recursos oferecidos pelo <em>vue-router</em> para a navegação. Reparem na diretiva <em>“:to”</em> que menciona através do<em> “name”</em> para qual componente apontaremos.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*ylxh1JG1AIMWm0SWJCndXw.png" /><figcaption>Código do componente Area1 — As outras áreas apenas mudam os apontamentos dos links</figcaption></figure><h3>O truque</h3><p>Entendo que a responsabilidade de saber onde cada rota está ou pertence dentro do ecossistema de uma aplicação ou site é da própria rota, logo, injetaremos em cada uma delas essa informação.</p><p>A forma como faremos isso será através da chave <em>meta</em> inserida na instância do <em>vue-router</em>. Dentro dela vamos mapear a rota e chamá-la de <em>breadcrumb</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*MNpvClnWMM4cdHGp2sMISA.png" /><figcaption>O formato do breadcrumb.</figcaption></figure><p>O que temos é um array de objetos em que cada um deles tem a chave <em>name</em> que será responsável pelo texto que aparecerá na tela e a chave <em>link,</em> que fará o apontamento para qual rota queremos acionar.</p><p>O nosso último objeto no array não tem o campo <em>link</em> e isso indica que ele é o componente atualmente renderizado na tela e por isso, não iremos apontar para ele próprio.</p><p>Com a rota configurada, metade do caminho já foi andado. Falta apenas uma etapa.</p><h3>…o Bradcrumb</h3><p>Com as rotas tendo o metadado <em>breadcrumb</em> fixados, exibir o caminho na tela ficou fácil. Contudo, como fazer isso de forma automática, sem precisar ficar chamando métodos ou apontando o local em cada chamada à nova rota é que é a graça desse componente.</p><p>O truque para que funcione de forma independente é vigiar a rota e a cada atualização checar qual o caminho está desenhado no <em>breadcrumb</em> que foi configurado e então renderizá-lo na tela.</p><p>Utilizaremos o hook <em>watch</em> no VueJS. Ele é responsável por observar mudanças em um determinado dado e o que faremos, obviamente, é vigiar a mudança de rota.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*OglVCgLsYlO56NepEJcCAw.png" /><figcaption>A cada mudança na rota ele atualiza a variável breadcrumbList com o caminho desenhado.</figcaption></figure><p>Tendo a garantia de que sempre que a rota mudar teremos a variável <em>breadcrumbList</em> atualizada, basta escrevermos ela de forma amigável na tela.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*WiVjcVHQO_XLVPzVFlA6NA.png" /><figcaption>Exemplo da exibição do nosso breadcrumb</figcaption></figure><p>Para isso, iteramos os objetos contidos na variável, pegamos os nomes e links e escrevemos na tela. Em casos que não há a chave <em>link</em> no objeto significa que caminho não é acessível e isso servirá para mostrar a nossa posição atual na aplicação.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*l6LiMcYYopuDWMP1_8P-dQ.png" /><figcaption>Renderizando o caminho na tela.</figcaption></figure><p>Cada item na nossa lista é clicável e ele aponta para um método chamado <em>routeTo()</em> que recebe o índice da lista. Esse índice será acessado dentro do método e então checaremos se ele é lincável ou não.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*nE6i0fzBp3UhmeD4Daui3g.png" /><figcaption>Checa se há um link e então o abre.</figcaption></figure><p>Para abrir o link do breadcrumb eu usei uma outra forma de interagir com o <em>vue-router</em> que é através do método <em>push</em>. O que ele faz é dar um push em uma nova rota.</p><p>O código completo do ficou assim:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*mY0-wzRj-bDUE4e9DrMdRw.png" /><figcaption>Breadcrumbs.vue</figcaption></figure><h3>O resultado…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*oDTxHoPHwNEU7DKDcwKFfw.gif" /></figure><h3>Finalizando…</h3><p>Para quem está iniciando com <em>VueJS</em>, saber o que um hook como <em>watch</em> pode lhe oferecer, compreender um pouco do poder do<em> vue-router</em> e absorver esse conceito de <em>componentização</em> é sem dúvidas primordial.</p><p>O código completo pode ser encontrado no github <a href="https://github.com/iFgR/vue-breadcrumbs">clicando aqui</a>. Qualquer dúvida, ficarei feliz em interagir através dos comentários aqui ou de issues criadas no github.</p><p>Espero poder ter acrescentado algo no seu conhecimento!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c06781d0320" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated Breadcrumbs with VueJS]]></title>
            <link>https://medium.com/@fagnersaraujo/automated-breadcrumbs-with-vuejs-7e1051de8028?source=rss-a37cf1e739b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e1051de8028</guid>
            <category><![CDATA[single-page-applications]]></category>
            <category><![CDATA[vue-router]]></category>
            <category><![CDATA[breadcrumbs]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[components]]></category>
            <dc:creator><![CDATA[Fagner Araujo]]></dc:creator>
            <pubDate>Mon, 12 Mar 2018 01:17:43 GMT</pubDate>
            <atom:updated>2018-03-12T01:17:43.573Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you need to put a breadcrumb on your site or application and are you thinking of adding a library to it? How about understanding what it is and how it works before? so that’s what we’re going to cover here.</p><h3>What is?</h3><p>Breadcrumb is a means of navigation within an application that allows the viewer to know exactly where he is. With that, he can return to a previous step or even better align their understanding of the application.</p><blockquote>“Breadcrumb is a means of navigation within an application that allows the viewer to know exactly where he is.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*4sujZH8UsNg5r5NsDAn6ng.png" /><figcaption>Breadcrumb example at the BBC website.</figcaption></figure><p>Observing the <em>BBC</em> website you notice that the subject is <strong>England</strong> and the matter is within the section <strong>London</strong> that belongs to <strong>Local News</strong> and <strong>Regions</strong>.</p><h3>What will we use?</h3><p>As the main framework we will use <strong>VueJS</strong>. If you have not used it,<a href="https://vuejs.org/v2/guide/">take a look at the official website and love it!</a></p><p>For the routes we will use the official Vue plugin called <strong>Vue-Router</strong>. You may know it in more detail <a href="https://router.vuejs.org/en/">here</a>.</p><h3>Starting a project from scratch</h3><blockquote>in this step we will create a project from scratch using <a href="https://github.com/vuejs/vue-cli"><strong><em>vue-cli</em></strong></a>. Is yout project has already been created, go to the next step— Preparing the ground.</blockquote><p>Vue-cli is a global library that can be installed with the command:</p><pre>npm install --global vue-cli</pre><p>To create a pre-configured project with webpack and everything else, run:</p><pre>vue init webpack breadcrumbs</pre><p>some basic questions will be made. Just reply by saying yes to the vue-router. Below is the configuration that I used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*_yoJCe6wrd1bEp6u7x8iQw.png" /><figcaption>Configuration used in this example.</figcaption></figure><p>With this step completed you will already have a folder structure ready and your first component created, in addition to your first route already created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*A2TI2CuwMX1e7l1TAFA-cQ.png" /><figcaption>Structure of folders with the first component and the route pointing to it.</figcaption></figure><h3>The basics of the vue-router</h3><p>In an SPA it is fundamental an engine that treats the routes. in VueJS the <em>vue-router</em> is the official engine.</p><p>A basic route is composed of <strong>path</strong>, <strong>name</strong>, and <strong>component</strong>. Where <strong>path</strong> keeps the URL path to be routed, <strong>name</strong> defines how can we call this route and <strong>component</strong> points to which component will render the route.</p><p>We will add a key called <strong>meta</strong> that will be responsible for the automation of our breadcrumb. We will see this later on.</p><h3>Preparing the ground</h3><p>Let’s start by creating four new components to be linked via links.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*r4DcVRcuG2qvCM3Xgdu2WQ.png" /><figcaption>Our four files. Area1, Area2, Area12 and Area 121</figcaption></figure><p>The structure set for the hierarchy is:</p><pre>Area 1<br>  Area 1 - 2<br>    Area 1 - 2 - 1<br>Area 2</pre><p>Pretty simple: <em>Area 1 — 2 — 1</em> is contained in <em>Area 1 — 2</em> which in turn is contained in <em>Area 1</em>.</p><p>The areas point to other areas using the <em>router-link</em>. The router-link is one of the features offered by the <em>vue-router</em> for navigation. Note the directive <em>“: to”</em> mentioning by <em>“name”</em> to which component will point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*ylxh1JG1AIMWm0SWJCndXw.png" /><figcaption>Area1 component code — the other areas only change the notes of the links.</figcaption></figure><h3>The trick</h3><p>I understand that the responsibility to know where each route is or belongs within the ecosystem of an application or site is the route itself, so we will inject each information into it.<br>The way we do this will be through the meta key inserted in the <em>vue-router</em> instance. Inside it we will map the route and call it <em>breadcrumb</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*MNpvClnWMM4cdHGp2sMISA.png" /><figcaption>The breadcrumb format.</figcaption></figure><p>What we have is an array of objects in which each of them has the key name that will be responsible for the text that will appear on the screen and the key <em>link</em>, which will make the point to which route we want to trigger.</p><p>Our last object in the array does not have the <em>link</em> field and this indicates that it is the currently rendered component on the screen and so we will not point to it itself.</p><p>With the route set, half way has already been walked. Only one step left.</p><h3>…the Breadcrumb</h3><p>With routes having the <em>breadcrumb</em> metadata fixed, displaying the path on the screen was easy. However, how to do this automatically, without having to keep calling methods or pointing the location on each call to the new route is what fun is about this component.</p><p>The trick to work independently is to monitor the route and with each update check which path is drawn in the <em>breadcrumb</em> that was configured and then render it on the screen.</p><p>We’ll use the hook <em>watch</em> on VueJS. He is responsible for observing changes in an item of data and what we will do, of course, is to watch the change of route.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*OglVCgLsYlO56NepEJcCAw.png" /><figcaption>At each route change it updates the breadcrumbList variable with the drawn path.</figcaption></figure><p>Having the assurance that when the route change will have the updated <em>breadcrumbList</em> variable, simply we write it friendly on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*WiVjcVHQO_XLVPzVFlA6NA.png" /><figcaption>Example view of our breadcrumb.</figcaption></figure><p>For this, we iterate the objects contained in the variable, we took the names and links and write on the screen. In case that there is no <em>link</em> key in object means that path is not accessible and this will serve to show our current position in the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*l6LiMcYYopuDWMP1_8P-dQ.png" /><figcaption>Rendering the path on the screen.</figcaption></figure><p>Each item in our list is clickable and it points to a method called <em>routeTo()</em> that receives the index from the list. This index will be accessed within the method and then we will check if it is indexable or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*nE6i0fzBp3UhmeD4Daui3g.png" /><figcaption>Check if there is a link and then opens.</figcaption></figure><p>To open the breadcrumb link I used another way of interacting with the <em>vue-router</em> which is through the <em>push</em> method. What it does is push on a new route.</p><p>The complete code looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*mY0-wzRj-bDUE4e9DrMdRw.png" /><figcaption>Breadcrumbs.vue</figcaption></figure><h3>The result…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*oDTxHoPHwNEU7DKDcwKFfw.gif" /></figure><h3>Finishing…</h3><p>For those who are starting with <em>VueJS</em>, knowing what a hook like <em>watch</em> can offer you, understanding a little of the power of the <em>vue-router</em> and absorbing this concept of <em>componentization</em> is without doubt primordial.</p><p>The complete code can be found on github by <a href="https://github.com/iFgR/vue-breadcrumbs">clicking here</a>. Any questions, I’ll be happy to interact through comments here or issues created in github.</p><p>I hope to have added something to your knowledge!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e1051de8028" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>