<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ViriCruz</title>
    <description>The latest articles on DEV Community by ViriCruz (@viricruz).</description>
    <link>https://dev.to/viricruz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F220108%2F357ed5e5-753f-4f55-948e-eaf94c8cad04.jpg</url>
      <title>DEV Community: ViriCruz</title>
      <link>https://dev.to/viricruz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/viricruz"/>
    <language>en</language>
    <item>
      <title>How to start practicing TDD while creating a reusable component with React</title>
      <dc:creator>ViriCruz</dc:creator>
      <pubDate>Sun, 18 Oct 2020 22:58:22 +0000</pubDate>
      <link>https://dev.to/viricruz/how-to-start-practicing-tdd-while-creating-a-reusable-component-with-react-1k9c</link>
      <guid>https://dev.to/viricruz/how-to-start-practicing-tdd-while-creating-a-reusable-component-with-react-1k9c</guid>
      <description>&lt;p&gt;&lt;em&gt;This article will try to teach how to practice test-driven development while at the same time teaching how to test a reusable react component.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Requirements before starting&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;You have installed node.js on your computer&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Ensure that &lt;code&gt;npx create-react-app app-name&lt;/code&gt; works in your terminal since we are going to use this to create the basic setup of the app&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Install enzyme &lt;code&gt;npm i -D enzyme&lt;/code&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Install enzyme adapter &lt;code&gt;npm i - D enzyme-adapter-react-16&lt;/code&gt; since we are using version 16 of React&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Create or edit&lt;/em&gt; &lt;strong&gt;src/setupTests.js&lt;/strong&gt; &lt;em&gt;to match the following code&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import '@testing-library/jest-dom/extend-expect';
import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

configure({
  adapter: new Adapter()
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that you have done this ensure that you can run the single test that comes with the setup when we created the app.&lt;/p&gt;

&lt;p&gt;Run &lt;strong&gt;npm test&lt;/strong&gt; in your terminal and press a to run all the tests, you will see a similar screen like the following:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HtkasKXw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4vv9nwp7n6nw5uuj5bu3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HtkasKXw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4vv9nwp7n6nw5uuj5bu3.PNG" alt="running first test"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have done this, let’s delete the test case in file &lt;strong&gt;src/App.test.js&lt;/strong&gt; to start creating our tests.&lt;/p&gt;

&lt;p&gt;What do we want to achieve? For this exercise we want to create a Button component that we can reuse multiple times inside our app, specifically we want to be able to set a different text every time we call the Button component.&lt;/p&gt;
&lt;h3&gt;
  
  
  Let’s Go!
&lt;/h3&gt;

&lt;p&gt;Ok, first, following the TDD principles, we need to create a failing test before creating any code for the Button component and App component.&lt;/p&gt;

&lt;p&gt;Before creating our tests, we are going to create a describe block and inside we are going to add beforeAll() function to create appWrapper before every test run that will keep our code DRY.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let appWrapper
  beforeAll(() =&amp;gt; {
    appWrapper = shallow(&amp;lt;App /&amp;gt;)
  })

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;appWrapper contains our App component.&lt;/p&gt;

&lt;p&gt;Now go to &lt;strong&gt;src/App.test.js&lt;/strong&gt; and the first test case will ensure that App component renders a Button component that will be our submit button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('renders a button component', () =&amp;gt; {
    const submitButton = appWrapper.find(SubmitButton)
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After writing this line we need to run the tests again and we can see that we have a failing test.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--feN1yG_g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dta16a8teoknoedy66cd.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--feN1yG_g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dta16a8teoknoedy66cd.PNG" alt="first failing test"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s move on to make the test green. Following the other step of TDD, we need to write only enough code to make the test green.&lt;/p&gt;

&lt;p&gt;Let’s create Button.js in the src folder with the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default() =&amp;gt; {}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And create the following jsx on App.js to return the Button component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import SubmitButton from './Button'

function App() {
  return &amp;lt;SubmitButton /&amp;gt;
}
export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, we need to import the Button component in &lt;strong&gt;src/App.test.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import App from './App';
import { shallow } from 'enzyme';
import SubmitButton from './Button'

describe('App', () =&amp;gt; {
  let appWrapper
  beforeAll(() =&amp;gt; {
    appWrapper = shallow(&amp;lt;App /&amp;gt;)
  })

  it('renders a button component', () =&amp;gt; {
    const submitButton = appWrapper.find(SubmitButton)
  })
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have our test in green.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q_rRzxVh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2w93j6u66j92jmz5xwnz.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q_rRzxVh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2w93j6u66j92jmz5xwnz.PNG" alt="first test green"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s finish this test by doing an assertion. We are going to inspect if the App contains one Button component by adding the following code to the first test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;expect(submitButton).toHaveLength(1)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Full test looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('renders a button component', () =&amp;gt; {
    const submitButton = appWrapper.find(SubmitButton)

    expect(submitButton).toHaveLength(1)
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensure that the test is still green.&lt;/p&gt;

&lt;p&gt;So far we’ve made a little bit of TDD by creating a Button component and render it in App component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s keep practicing!
&lt;/h3&gt;

&lt;p&gt;Our second test is going to inspect if we are passing a prop called value to the Button component&lt;/p&gt;

&lt;p&gt;Let’s create a failing test&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('pass value as prop', () =&amp;gt; {
    const submitButton = appWrapper.find(SubmitButton)

    expect(submitButton.props().value).toBeDefined()
  })

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are expecting a prop called value to be defined in the Button component but we received an undefined value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---H1z0Xza--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bkk75qfyhhc27qw5gsmd.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---H1z0Xza--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bkk75qfyhhc27qw5gsmd.PNG" alt="second failing test"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s make this test green!&lt;br&gt;
To make the test pass, we need to pass a prop called value in the Button component inside the App component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function App() {
  return &amp;lt;SubmitButton value="" /&amp;gt;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now our test is green again, congrats!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7SYRs162--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1bv2r8h2p4fxht0nlyxp.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7SYRs162--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1bv2r8h2p4fxht0nlyxp.PNG" alt="second test green"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s do another test to keep practicing TDD, remember practice makes perfect!&lt;br&gt;
For this test, we want to inspect if the value prop is equal to the string “Submit” so we are going to create another failing test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it("has a value prop equal to 'Submit'", () =&amp;gt; {
    const submitButton = appWrapper.find(SubmitButton)

    expect(submitButton.props().value).toEqual('Submit')
  })

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can imagine this test is going to fail&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nNUTuaYy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n50v9ngol9bfz8je9neb.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nNUTuaYy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n50v9ngol9bfz8je9neb.PNG" alt="third failing test"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need to refactor the Button component inside the App component to make the test green.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import React from 'react';
import SubmitButton from './Button'

function App() {
  return &amp;lt;SubmitButton value="Submit" /&amp;gt;
}
export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;YES!&lt;/strong&gt;, all the three tests are passing now &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xVRhxhrT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xek6g72e0ockzfga5yhh.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xVRhxhrT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xek6g72e0ockzfga5yhh.PNG" alt="third test green"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you get here, Well done! you now have a clear idea of what Test-driven development is.&lt;br&gt;
Just to recap:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;write a failing test, just enough code to make the test fails&lt;/li&gt;
&lt;li&gt;refactor only the necessary code to make the test green&lt;/li&gt;
&lt;li&gt;Then again, write a failing test and then refactor to make the test green and so on&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And for final touches, as you can see we are repeating &lt;code&gt;const submitButton = appWrapper.find(SubmitButton)&lt;/code&gt; across all our test cases, so let’s refactor this to make our code DRY&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let appWrapper, submitButton
  beforeAll(() =&amp;gt; {
    appWrapper = shallow(&amp;lt;App /&amp;gt;)
    submitButton = appWrapper.find(SubmitButton)
  })

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can safely delete &lt;code&gt;const submitButton = appWrapper.find(SubmitButton)&lt;/code&gt; in every test and our test will still be green.&lt;/p&gt;

&lt;p&gt;Full code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import App from './App';
import { shallow } from 'enzyme';
import SubmitButton from './Button'

describe('App', () =&amp;gt; {
  let appWrapper, submitButton
  beforeAll(() =&amp;gt; {
    appWrapper = shallow(&amp;lt;App /&amp;gt;)
    submitButton = appWrapper.find(SubmitButton)
  })

  it('renders a button component', () =&amp;gt; {

    expect(submitButton).toHaveLength(1)
  })

  it('pass value as prop', () =&amp;gt; {

    expect(submitButton.props().value).toBeDefined()
  })

  it("has a value prop equal to 'Submit'", () =&amp;gt; {

    expect(submitButton.props().value).toEqual('Submit')
  })
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Additional Resources
&lt;/h4&gt;

&lt;p&gt;A great resource that explains in a very clear way how to do TDD:&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=tX-gu6FWcsE"&gt;TDD Live Coding - Test Driven Development Tutorial with React, Jest, and Enzyme&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Find me at &lt;a href="//github.com/ViriCruz"&gt;github.com/Viricruz&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Happy Testing!!
&lt;/h2&gt;

</description>
    </item>
    <item>
      <title>Fetch with Promise.all and async / await</title>
      <dc:creator>ViriCruz</dc:creator>
      <pubDate>Mon, 06 Jul 2020 19:56:23 +0000</pubDate>
      <link>https://dev.to/viricruz/fetch-with-promise-all-and-async-await-4ioe</link>
      <guid>https://dev.to/viricruz/fetch-with-promise-all-and-async-await-4ioe</guid>
      <description>&lt;h1&gt;
  
  
  &lt;strong&gt;Fetch with promise.all and async / await&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;This article is focusing on showing a brief explanation of how to use Promise.all in a real example that I used in one of my recent projects.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can check the project in the following &lt;a href="https://github.com/ViriCruz/basic-catalogue-react"&gt;github repository&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Promise.all
&lt;/h2&gt;

&lt;p&gt;Executes promises in parallel and it waits until all of them are ready. Promise.all takes an array of promises and returns a new promise.&lt;/p&gt;

&lt;h2&gt;
  
  
  The scenario we are going to use and why Promise.all is useful in this example.
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Public API we are going to use to fetch data:&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://pokeapi.co/api/v2/type/"&gt;https://pokeapi.co/api/v2/type/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check the &lt;a href="https://pokeapi.co/docs/v2"&gt;official docs&lt;/a&gt; for more information.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;What do we want to achieve&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;We want to show a list of pokemon with the name of the pokemon with its respective image.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Obstacles&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://pokeapi.co/api/v2/type/1"&gt;https://pokeapi.co/api/v2/type/1&lt;/a&gt; returns a list of pokemon that contains the name but not the image URL, instead, it returns a URL where we can fetch more details of the pokemon including the image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--784spkTf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/SfF9CnY.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--784spkTf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/SfF9CnY.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;How to solve this case using ES6&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;One way to solve this is using &lt;em&gt;&lt;code&gt;Promise.all&lt;/code&gt;&lt;/em&gt;, as we need to wait for all the promises to resolve (we are talking about fetching to the URL that we retrieved in the first fetch) to populate the list of pokemon with the name and the respective image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to combine Promise.all with fetch, map, async and await to make a cleaner code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchPokemon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;initial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://pokeapi.co/api/v2/type/1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;initialJson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="c1"&gt;//console.log(initialJson.pokemon) // data array&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;detailsData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;initialJson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pokemon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;preFetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pokemon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;preFetchData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;

    &lt;span class="c1"&gt;// uncomment this code if you want to see how it looks await Promise.all(detailsData)&lt;/span&gt;
    &lt;span class="c1"&gt;// const response = await Promise.all(detailsData)&lt;/span&gt;
    &lt;span class="c1"&gt;// console.log(response)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;detailsData&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sprites&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;front_default&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}))&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;fetchPokemon&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;With the code above, we'll have an array of objects which contain the name and image in each item. This array is ready to use to create a list with HTML and achieve what we pretend.&lt;/p&gt;
&lt;h4&gt;
  
  
  Live Code
&lt;/h4&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@ViriCruz/fetch-from-pokeapico?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;



&lt;p&gt;I hope this can help you, there is a ton of use cases where you can apply &lt;code&gt;Promise.all&lt;/code&gt;, this is just one of them and, feel free to comment on this article if you like.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>babel</category>
    </item>
    <item>
      <title>How to use eslint with webpack / ES6 / modules</title>
      <dc:creator>ViriCruz</dc:creator>
      <pubDate>Thu, 05 Mar 2020 23:48:24 +0000</pubDate>
      <link>https://dev.to/viricruz/how-to-use-eslint-with-webpack-es6-modules-4i4i</link>
      <guid>https://dev.to/viricruz/how-to-use-eslint-with-webpack-es6-modules-4i4i</guid>
      <description>&lt;p&gt;Today we are going to talk about eslint and webpack. This is not going to teach you how to install eslint in your project, I will assume that you already did.&lt;/p&gt;

&lt;p&gt;First of all, when you are new to &lt;em&gt;eslint&lt;/em&gt; and want to &lt;em&gt;&lt;strong&gt;auto-fix&lt;/strong&gt;&lt;/em&gt; your JavaScript files, so you run &lt;code&gt;npx eslint --fix . &lt;/code&gt; but, you have this &lt;em&gt;main.js&lt;/em&gt; that webpack kindly generated for you to make your code separated by modules, work.&lt;/p&gt;

&lt;p&gt;So, you get this result ▶️&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CXoYV80V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/QxtyVRiv66gUVWCdZZgZ4OzXTVxzqvIu5btgF_AUsv4WVU1lR-VKz5iQ6ptKP499-gWhAdplZ-bDr1M3kbknCow7AreYvwwOn5oZL9gP%3Ds1600" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CXoYV80V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/QxtyVRiv66gUVWCdZZgZ4OzXTVxzqvIu5btgF_AUsv4WVU1lR-VKz5iQ6ptKP499-gWhAdplZ-bDr1M3kbknCow7AreYvwwOn5oZL9gP%3Ds1600" alt="main.js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even though the code still working, you are not going to pass eslint rules. We don’t need to check this file with eslint, so what do we do?&lt;/p&gt;

&lt;p&gt;We need to create a file in the root directory called &lt;em&gt;.eslintignore&lt;/em&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AutDsIUb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh5.googleusercontent.com/3d6fdeH74V_3XMg-tafLi0SfO3Zx7VsZpX6vw9rYqBrNNxApp_r7SMDz76xL8UIczlRhKA9PFG2Gwn-6z9Jsuex5kkpz9qiaM3_gwUNC%3Ds1588" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AutDsIUb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh5.googleusercontent.com/3d6fdeH74V_3XMg-tafLi0SfO3Zx7VsZpX6vw9rYqBrNNxApp_r7SMDz76xL8UIczlRhKA9PFG2Gwn-6z9Jsuex5kkpz9qiaM3_gwUNC%3Ds1588" alt=".eslintignore"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the only line of code that you need to write is &lt;em&gt;dist/main.js&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And that's it, next time you use &lt;code&gt;npx eslint .&lt;/code&gt; or &lt;code&gt;npx eslint --fix .&lt;/code&gt; eslint will &lt;strong&gt;ignore&lt;/strong&gt; this file.&lt;/p&gt;

&lt;p&gt;If you want to check it out directly from the official documentation, go to the next link &lt;a href="https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories"&gt;https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Coding! 😄&lt;/p&gt;

</description>
      <category>eslint</category>
      <category>es6</category>
      <category>webpack</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Newbie notes while learning rails</title>
      <dc:creator>ViriCruz</dc:creator>
      <pubDate>Sat, 14 Sep 2019 02:56:18 +0000</pubDate>
      <link>https://dev.to/viricruz/newbie-notes-while-learning-rails-383m</link>
      <guid>https://dev.to/viricruz/newbie-notes-while-learning-rails-383m</guid>
      <description>&lt;p&gt;This a small diary...📓&lt;br&gt;
If you are using heroku to deploy your app and a database, don’t forget to run &lt;code&gt;heroku run rails db:migrate&lt;/code&gt; after &lt;code&gt;git push heroku master&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can use multiple rails version, useful if you are following a tutorial from a previous version than the current version. Just don’t forget &lt;strong&gt;underscores&lt;/strong&gt; while &lt;code&gt;rails &lt;em&gt;5.1.6&lt;/em&gt; new app_title&lt;/code&gt; where 5.1.6 can be another version.&lt;/p&gt;

&lt;p&gt;If you modify your &lt;strong&gt;Gemfile&lt;/strong&gt; don’t forget to &lt;code&gt;bundle install&lt;/code&gt; after the changes.&lt;/p&gt;

&lt;p&gt;Always check if at some point of the code the &lt;strong&gt;colon&lt;/strong&gt; is in front of the variable like &lt;code&gt;name:&lt;/code&gt; or if it’s in back &lt;code&gt;:name&lt;/code&gt;, this always put me in trouble while learning rails.&lt;/p&gt;

&lt;p&gt;This are things happening right now to me while learning and if you feel like sharing your experience while you were learning rails please add a comment 😋 &lt;/p&gt;

</description>
      <category>rails</category>
      <category>heroku</category>
    </item>
    <item>
      <title>How to return multiple values in ruby</title>
      <dc:creator>ViriCruz</dc:creator>
      <pubDate>Thu, 29 Aug 2019 19:33:37 +0000</pubDate>
      <link>https://dev.to/viricruz/how-to-return-multiple-values-in-ruby-1cb</link>
      <guid>https://dev.to/viricruz/how-to-return-multiple-values-in-ruby-1cb</guid>
      <description>&lt;p&gt;You can return &lt;code&gt;multiple values&lt;/code&gt; on a method using comma-separated values when you return the data.&lt;/p&gt;

&lt;p&gt;Check the example below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;multiple_values&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are creating a method called &lt;code&gt;multiple_values&lt;/code&gt; that return 4 values. Each of them separated by a comma, in this form when we call &lt;code&gt;multiple_values&lt;/code&gt; as a result, we will see an array with all these values. So the first one 1 will be at &lt;code&gt;position 0&lt;/code&gt; of the array, 2 will be at &lt;code&gt;position 1&lt;/code&gt;, 3 will be at &lt;code&gt;position 2&lt;/code&gt; and the last value 4 will be at &lt;code&gt;position 3&lt;/code&gt; of the array.&lt;/p&gt;

&lt;p&gt;Let’s call our &lt;code&gt;multiple_values&lt;/code&gt; method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;print_values&lt;/span&gt;
  &lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;multiple_values&lt;/span&gt;

  &lt;span class="n"&gt;_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;
  &lt;span class="n"&gt;_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;_3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;_4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nb"&gt;p&lt;/span&gt; &lt;span class="s2"&gt;"first - &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;_1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, two - &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;_2&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, three - &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;_3&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, four - &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;_4&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; 
  &lt;span class="c1"&gt;# =&amp;gt; "first - 1, two - 2, three - 3, four - 4"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;print_values&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Calling the method
&lt;/h3&gt;

&lt;p&gt;We created a method called &lt;code&gt;print_values&lt;/code&gt; that will print the &lt;strong&gt;values&lt;/strong&gt; of the array returned by &lt;code&gt;multiple_values&lt;/code&gt; method.&lt;br&gt;
As you can see we store the array returned by &lt;code&gt;multiple_values&lt;/code&gt; in a variable called &lt;code&gt;values&lt;/code&gt;, this &lt;code&gt;values&lt;/code&gt; now contain all the values that we returned before. So for this example to show clearly what &lt;code&gt;values&lt;/code&gt; contain we created a &lt;em&gt;variable&lt;/em&gt; for each value of the array. Variable &lt;code&gt;_1&lt;/code&gt; called a shortcut method of the array to &lt;code&gt;retrieve&lt;/code&gt; the first element of the array even though it will work exactly the same way as &lt;code&gt;values[0]&lt;/code&gt;. Then we have the rest of the variables &lt;code&gt;_2, _3, _4&lt;/code&gt; to store the remaining values.&lt;/p&gt;

&lt;p&gt;In the last line of the method, we print with a custom format the variables. So to make this work don’t forget to call &lt;code&gt;print_values&lt;/code&gt; to see what it does.&lt;/p&gt;

&lt;p&gt;If you are the kind of person that likes to play with the code. Here is the link of the live version &lt;a href="https://repl.it/@ViriCruz/multiplevalues"&gt;https://repl.it/@ViriCruz/multiplevalues&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to play around with the code.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>vscode</category>
    </item>
  </channel>
</rss>
