Jest and the Component Driven Development (CDD) – Comunidad JS – Medium

#Jest and the Component Driven Development (CDD):  #ReactJS #JavaScript

  • Jest and the Component Driven Development (CDD)Testing React and React Native applications.We all knows about TDD right ?
  • I recently discovered other flow/flavor around React Components and Jest snapshot testing that makes me more happy and encourage me to write more tests.This approach makes the dev process a bit more fun that the other way around.
  • Then, when you´re confortable with your component code base and you have applied all the good practices out there, write the actual test, passing the required props to the component being tested and expect it to match the snapshot.Snapshot testingSnapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.The above statement, is from the Jest documentation, and it´s 100% true.
  • I’ve found snapshot testing to be a quick and fun way to test Components and make sure your UI does not change unexpectedly, which is a good thing.The test will fail if the two images do not match: either the change is unexpected, or the screenshot needs to be updated to the new version of the UI component.That means we are not passing the expected props to our component in some parts of our application or we have adjusted the component (because we´ve refactored it).
  • So either one or the other possibility, we need to update the test snapshot (If we´ve refactored it) executing in the terminal yarn test -u or go and fix the part in the application where we´re not using the component as we expect.Having a test coverage between 80 and 100% make us more confidents when we need to deploy to any environment and allows applications to be more robust and easy to scale.In closing, I really encourage React developers to use Jest for testing applications.

We all knows about TDD right ? Test Driven Development.
The philosophy behind it, is to start the development cycle with first writing a failing test and then writing the actual function, to make it…
Continue reading “Jest and the Component Driven Development (CDD) – Comunidad JS – Medium”

8 things to learn in React before using Redux

  • A component can manage a whole lot of state, pass it down as props to its child components and pass a couple of functions along the way to enable child components to alter the state in the parent component again.
  • Component A is the only component that manages local state but passes it down to its child components as props.
  • In addition, it passes down the necessary functions to enable B and C to alter its own state in A.

    Now, half of the local state of component A is consumed as props by component C but not by component B.

  • When you lift the local state management down to component C, all the necessary props don’t need to traverse down the whole component tree.
  • When a library such as Redux “connects” its state managements layer with React’s view layer, you will often run into a higher order component that takes care of it (connect HOC in react-redux).

Facts about React that should be known before using Redux (or MobX). Most important: Learn React first, then opt-in Redux…
Continue reading “8 things to learn in React before using Redux”

Intro to React – Christopher Hague – Medium

Intro to React  #learning #react #javascript #programming #learningtocode #reactjs

  • Here is another representation of how we can conceptualize our component hierarchy:- Application – Search Bar – Product Table – Category – ProductThe Trickle Down EffectHow does our application use each of the components to interact with one another?
  • In the same way that functions rely on arguments to operate on and manipulate data, components rely on props that are given as a they being declared.Using the example from above, it becomes easier to conceptualize how the Product and Category components are rendering the appropriate information onto the screen.
  • When the Product Table component is declared within the Application component, the Application will pass down this information related to all of the products to the Product Table as props.
  • As such, the Search Bar component will inherit a set of functions that define how the products in the API will be filtered based on the user input.The Category and Product components will then rely on the props passed down from Product Table to render the list of items, using the Search Bar component to filter the products based on the search terms and render only those products to the screen.
  • Conversely, if the search bar is empty then each product in the collection will be rendered.Divide and ConquerNow that we have some idea of how we want each of our components to function, let’s sketch each of them out below to get some idea of how the code for the app might look:class Category extends React.Component { // renders categories}class Product extends React.Component { // renders products}class ProductTable extends React.Component { // declares a Category and Product component, passing props to each of them Category category={product.category} key={product.category} / Product product={product} key={product.name} / // renders Category, Product}class SearchBar extends React.Component { // renders SearchBar // filters based on search terms}class Application extends React.Component { // renders SearchBar and ProductTable components, passing props to each of them SearchBar / ProductTable products={this.props.products} /}Now that we have all of our components defined, rendering the application to the screen becomes as simple as using the ReactDOM.render function and passing the Application component to it.ReactDOM.render( Application products={PRODUCTS} /,

React is a declarative, component-based JavaScript library used for building user interfaces. It was created by Facebook employee Jordan Walke and was first deployed on Facebook and Instagram in 2011…
Continue reading “Intro to React – Christopher Hague – Medium”

8 things to learn in React before using Redux

  • A component can manage a whole lot of state, pass it down as props to its child components and pass a couple of functions along the way to enable child components to alter the state in the parent component again.
  • Component A is the only component that manages local state but passes it down to its child components as props.
  • In addition, it passes down the necessary functions to enable B and C to alter its own state in A.

    Now, half of the local state of component A is consumed as props by component C but not by component B.

  • When you lift the local state management down to component C, all the necessary props don’t need to traverse down the whole component tree.
  • When a library such as Redux “connects” its state managements layer with React’s view layer, you will often run into a higher order component that takes care of it (connect HOC in react-redux).

Facts about React that should be known before using Redux (or MobX). Most important: Learn React first, then opt-in Redux…
Continue reading “8 things to learn in React before using Redux”

React Ecosystem Setup — Step-By-Step Walkthrough – codeburst

#ReactJS Ecosystem Setup — Step-By-Step Walkthrough:

  • DOCTYPE htmlhtml lang=”en”head meta charset=”UTF-8″ meta name=”viewport” content=”width=device-width, initial-scale=1.0″ meta http-equiv=”X-UA-Compatible” content=”ie=edge” titleReact – Basic Setup/title/headbody div Express ServerRun npm install express.
  • It’ll recursively go through every dependency and the dependencies’ dependencies, resolving all the way down.It’ll transpile our farm-fresh, cutting-edge ES6+ down to ES5 so that it’ll work on virtually every browser.It’ll minify our code by removing whitespace and shortening variable names, reducing the final file size.In the end, we’ll be able to write modular, modern Javascript and CSS that we can work with easily and use best practices on.Getting StartedLet’s create a folder named src in our root directory.
  • DOCTYPE htmlhtml lang=”en”head meta charset=”UTF-8″ meta name=”viewport” content=”width=device-width, initial-scale=1.0″ meta http-equiv=”X-UA-Compatible” content=”ie=edge” titleReact – Basic Setup/title/headbody div you open up dist/app.
  • To make webpack minify your code, use the production flag, -p. Type in webpack -p and look at the bundle file.
  • js$/, exclude: [/node_modules/], use: { loader: ‘babel-loader’, options: { presets: [‘env’] } } } ] }};This code is telling webpack to test the files in our directory and look for the filenames matching the r

React is arguably the hottest framework currently used by the web development community at this point. Unfortunately, for newcomers and even more seasoned developers, setting up the industry-standard…
Continue reading “React Ecosystem Setup — Step-By-Step Walkthrough – codeburst”

React Ecosystem Setup — Step-By-Step Walkthrough

  • An issue with using a bundle instead of our source code is that it makes debugging more difficult, because the stack trace now refers to our bundle file.
  • Using the flag during development means webpack will watch our files and re-generate the bundle every time we save a change.
  • This code is telling webpack to test the files in our directory and look for the filenames matching the regex in the property.
  • Now we can use ES6 code and the bundle generated by webpack will contain only ES5 code.
  • We’ll have to add a term to our file to tell it that we’re writing React code.

Understand what React, Webpack, and Babel are doing and how to configure them yourself.
Continue reading “React Ecosystem Setup — Step-By-Step Walkthrough”