<?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 Kyle DiPeppe on Medium]]></title>
        <description><![CDATA[Stories by Kyle DiPeppe on Medium]]></description>
        <link>https://medium.com/@jkdipeppe?source=rss-f08409d29874------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*obGjiqw4Yg9aA65fm3zX1Q@2x.jpeg</url>
            <title>Stories by Kyle DiPeppe on Medium</title>
            <link>https://medium.com/@jkdipeppe?source=rss-f08409d29874------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 21:06:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jkdipeppe/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[How To Create a Simple Redux Store With a Counter]]></title>
            <link>https://medium.com/@jkdipeppe/how-to-create-a-simple-redux-store-with-a-counter-19dcc80d3b0?source=rss-f08409d29874------2</link>
            <guid isPermaLink="false">https://medium.com/p/19dcc80d3b0</guid>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Kyle DiPeppe]]></dc:creator>
            <pubDate>Mon, 20 Aug 2018 00:52:04 GMT</pubDate>
            <atom:updated>2018-08-20T00:52:04.099Z</atom:updated>
            <content:encoded><![CDATA[<p>How To Create a Simple Redux Store With a Counter</p><ol><li>Lets start off with a creating a react app:</li></ol><p>Open up your terminal and navigate to a fold of your choosing (or create a new folder with mkdir my-new-folder and then cd my-new-folder to move into that folder ). Once here lets run run the command create-react-app my-first-redux-store which is will create a new react application called my-first-redux-store. Lets open this in an IDE, I have Atom installed so I’m going to run atom . which will open my react app.</p><p>2. Installing dependancies</p><p>Lets npm install the necessary dependancies for our application to use redux.</p><p>Run npm install redux react-redux --save to do this.</p><p>3. Creating the store</p><p>Lets add a createStore.js file within our src folder. In this folder we want to have a createStore function that will allow us to setup a store in our index.js</p><p>Once you have the file lets add the following code</p><pre>//this is in ./src/createStore.js</pre><pre>export default function createStore(reducer) {<br>  let state;</pre><pre>function dispatch(action) {<br>    state = reducer(state, action);<br>    render();<br>  }</pre><pre>function getState() {<br>    return state;<br>  }</pre><pre>dispatch({ type: &#39;@@INIT&#39; });</pre><pre>return {<br>    getState,<br>    dispatch<br>  }<br>}</pre><pre>function render() {<br>  const container = document.getElementById(&#39;container&#39;);<br>}</pre><p>5. Creating a Reducer</p><p>First, add a new folder to the src folder in your react app called ‘reducers’.</p><p>Then we can add a file called itemCounterReducer.js which will allow us to increase the state of items in our Redux Store by adding the following code</p><pre>//this is in ./src/reducers/itemCounterReducer.js</pre><pre>export default function itemCounterReducer(state = {<br>  items: 0<br>}, action) {<br>  switch(action.type) {</pre><pre>case &#39;INCREASE_COUNT&#39;:<br>      return Object.assign({}, state, { items: state.items + 1});</pre><pre>default:<br>      return state;<br>  }<br>}</pre><p>This code creates a reducer called itemCounterReducer that has an initial key/value pair of items: 0 in state. If the action dispatched is INCREASE_COUNT then it will increase the count of items by 1.</p><p>6. Importing createStore and itemCounterReducer in index.js</p><p>Now that we can create a store and have a reducer lets go to index.js and import the following at the top-</p><pre>import { createStore } from &#39;redux&#39;;<br>import itemCounterReducer from &#39;./reducers/itemCounterReducer.js&#39;; //added code</pre><p>7. Lets create a store with a simple reducer</p><p>After adding the imports at the top you can now create a store and give your App access to the store. Lets add the code below</p><pre>//this is in ./src/index.js</pre><pre>import React from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom&#39;;<br>import { createStore } from &#39;redux&#39;; //added code above<br>import itemCounterReducer from &#39;./reducers/itemCounterReducer.js&#39;; //added code from above<br>import &#39;./index.css&#39;;<br>import App from &#39;./App&#39;;<br>import registerServiceWorker from &#39;./registerServiceWorker&#39;;</pre><pre>const store = createStore(itemCounterReducer, //added code<br>window.__REDUX_DEVTOOLS_EXTENSION__ &amp;&amp; //added code<br>window.__REDUX_DEVTOOLS_EXTENSION__()); //added code</pre><pre>ReactDOM.render(<br>    &lt;App store = {store} /&gt;, //added code<br>  document.getElementById(&#39;root&#39;));<br>registerServiceWorker();</pre><p>What we have done is created a store and stored it in a constant called store where we then pass this store to the App.js component.</p><p>We also pass in the reducer we created when we create this store.</p><p>8. Lets connect Everything in App.js</p><p>In App.js we want to make sure we import everything necessary at the top.</p><pre>import React, { Component } from &#39;react&#39;;<br>import { connect } from &#39;react-redux&#39;; //lets add this code<br>import &#39;./App.css&#39;;</pre><p>Next, we want to access the state and map it to props with the following function</p><pre>// this goes within ./src/App.js</pre><pre>const mapStateToProps = (state) =&gt; {<br>  return { items: state.items };<br>};</pre><p>And finally we want to make sure that we export this connection</p><pre>export default connect(mapStateToProps)(App);</pre><p>9. Tying it All Together</p><p>Finally, lets display and handle increasing the items count.</p><p>We want to display the current count and add a button so we can increase that count. Let do the following within the render() {return( )}</p><pre>render() {<br>    return (<br>      &lt;div className=&quot;App&quot;&gt;<br>        &lt;p&gt;{this.props.items} is the current count&lt;/p&gt;<br>        &lt;button onClick={() =&gt; this.handleOnClick()}&gt;<br>          Click<br>        &lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }</pre><p>Here we are adding a div that will have a paragraph that displays the items which we are getting from the function mapStateToProps we made above and adding a button where we can increase the count. Notice that we have a this.handlOnClick() when we click the button, we want to add that now.</p><p>10. Making it All Work!</p><p>Lets add in a handleOnClick() now which will tie everything together.</p><pre>class App extends Component {</pre><pre>// added code start</pre><pre>  handleOnClick() {<br>    this.props.dispatch({<br>      type: &#39;INCREASE_COUNT&#39;,<br>    })<br>  }</pre><pre>// added code end</pre><pre>render() {<br>    return (<br>      &lt;div className=&quot;App&quot;&gt;<br>        &lt;p&gt;{this.props.items} is the current count&lt;/p&gt;<br>        &lt;button onClick={() =&gt; this.handleOnClick()}&gt;<br>          Click<br>        &lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>} </pre><p>This will be called when we click our button. It will call dispatch which is automatically provided by connect. This sends the type: &#39;INCREASE_COUNT&#39; which will increase the count of items and automatically update App since the state is being changed. Here we can now run our app with npm start in the Terminal and see the magic happen!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19dcc80d3b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write Your First Cypress test]]></title>
            <link>https://medium.com/@jkdipeppe/write-your-first-cypress-test-14cd9d3d6b?source=rss-f08409d29874------2</link>
            <guid isPermaLink="false">https://medium.com/p/14cd9d3d6b</guid>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[test]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[promises]]></category>
            <dc:creator><![CDATA[Kyle DiPeppe]]></dc:creator>
            <pubDate>Thu, 09 Aug 2018 15:42:05 GMT</pubDate>
            <atom:updated>2018-08-10T17:01:32.648Z</atom:updated>
            <content:encoded><![CDATA[<p>Cypress- The testing suite you didn’t know you knew.</p><p>My setup: Working on a 15in MacBook Pro with <a href="https://atom.io/">Atom</a> installed as my editor of choice.</p><ol><li><strong>Set-up</strong> *(this can be skipped because a command in step 3 will also install cypress on your machine while setting up cypress as a dev dependency for your project)</li></ol><p>To get started with cypress its a pretty basic npm install. Just type npm install cypress in the command line of your Terminal. Doing this will install cypress on your machine and you are ready to navigate to whatever directory you wish to start writing your tests.</p><p><strong>2. New Folder</strong></p><p>Lets make a folder called my-cypress-tests and navigate into it by typing mkdir my-cypress-tests and then cd my-cypress-tests.</p><p>mkdir creates the folder and cd will change directories and move you into that folder (you should now see my-cypress-tests in the command line of your terminal to indicate that you are in the folder.</p><p><strong>3. Create Cypress Dependancies</strong></p><p>Once again in the command line, type npm install cypress --save-dev . This will install cypress locally (which I why I said you could skip step 1) and create a folder called node_modules which has all the dev dependencies for cypress for your project.</p><p><strong>4. Open Cypress/Tests Folder</strong></p><p>Now, again in your terminal, type ./node_modules/.bin/cypress open .</p><p>This will open Cypress and also create a folder in your project called cypress and within that folder will be a folder called integration . integration is the folder that will have you test files and there is a folder in it called examples that, as you can guess, has some cypress test examples. Lets close the Cypress window and go back to our Terminal command line.</p><p><strong>5. Open Atom</strong></p><p>In the command line type atom . (yes, the period is part of the command you type) which will open the current folder (in this case my-cypress-tests ) in Atom.</p><p><strong>6. Creating Our First Test File</strong></p><p>I know, quite a bit of setup but we can finally make our first test file!</p><p>In Atom open cypress/integration . This is where we want to create our first test file. If you right click on the integration folder you can select New File . Lets call this file sample_spec.js .</p><p><strong>7. Writing Our First Cypress Test</strong></p><p>About time, lets just get right into it.</p><p>In your sample_spec.js file in Atom lets try typing the following and save your code.</p><pre>describe(&#39;Visit Site&#39;, () =&gt; {<br>  it(&#39;Check if True is True&#39;, function() {<br>    expect(true).to.equal(true)<br>  })<br>})</pre><p><strong>8. Open and Run Cypress Tests</strong></p><p>Back in your command line type npx cypress open . This is the same command as earlier to open Cypress. This time you should see your sample_spec.js file in the INTEGRATION TESTS folder. All you have to do is click on this file and it should open up a browser and run your test.</p><p>You should see the webpage (if you are navigating/testing one) to the right and the tests that are running on the left. You have just written and passed your first Cypress Assertion Test!</p><p><strong>9. Test Website Functionality</strong></p><p>A nice website you can practice writing and running tests on (aside from your own) is this demo <a href="http://todomvc.com/examples/react/#/">ToDo React</a> site . Lets write a quick test that will make sure you can navigate to the site and create a ToDo. First lets create a new file by right clicking on the integrationFolder in Atom and selecting New File. Lets name that folder create_todo_spec.js. In this file lets type the following code.</p><pre>describe(&#39;Create a todo&#39;, () =&gt; {<br>  it(&#39;Visits ToDo&#39;, function() {<br>    cy.visit(&#39;<a href="https://todomvc.com/examples/react/#/&#39;">https://todomvc.com/examples/react/#/&#39;</a>)<br>  })</pre><pre>  it(&#39;types/submits ToDo&#39;, function() {<br>    cy.get(&#39;[data-reactid=&quot;.0.0.1&quot;]&#39;)<br>      .type(&#39;My first ToDo{enter}&#39;)<br>  })<br>})</pre><p>Once you save this file go back Cypress. You should now see this spec file under INTEGRATION TESTS as well. If you haven’t done so already you can click ‘Stop’ in the upper right to stop running your sample_spec.js and then click on the create_todo_spec.js. This will run this file and in doing so you should see a new window open, it will navigate to the ToDo React site, type in ‘My first ToDo!’ and create that todo. Pretty neat!</p><p><strong>Summary:</strong></p><p>Cypress is a very useful tool for testing. It is a testing framework written in JavaScript and, just like React, uses promises and async functions. As you can see, the tests in Cypress read quite easily which makes it fairly simple to pick up. Cypress has some very good documentation where you can see a full list of assertions and built in functions that come with it <a href="https://docs.cypress.io/guides/references/assertions.html#">here</a>.</p><p><a href="https://docs.cypress.io/guides/getting-started/installing-cypress.html#">Cypress setup/install</a></p><p><a href="https://docs.cypress.io/guides/references/assertions.html#">Cypress Assertions</a></p><p><a href="https://docs.cypress.io/guides/references/best-practices.html">Cypress Best Practices</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14cd9d3d6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>