Unit testing with Jest: Redux + async actions + fetch

  • Unit testing with Jest: Redux + async actions + fetchUsing Jest v20LAST UPDATE: June 24, 2017.
  • Ok, now, let’s test it step by step based on the WritingTests from the Redux docs.A big change here since I first wrote this article in 2016 is that Jest now does not mock your dependencies automatically like it used to.
  • /api’;import configureMockStore from ‘redux-mock-store’import thunk from ‘redux-thunk’const middlewares = [ thunk ];const mockStore = I am also going to write a helper method to mock the fetch response (we don’t need nock as suggested in the Redux Writing Test example):const mockResponse = (status, statusText, response) = { return new window.Response(response,…
  • Do you remember the import at the beginning of our example action code?import ‘whatwg-fetch’If you or your team forget to use the polyfill version of fetch, Chrome or FF will still work and you won’t notice it!
  • Thanks to the Redux docs for the great explanation of how we can test those async actions and for the mocha example (2017 note: They changed the example to use Jest!)

I have been using Jest since its beginnings. I won’t lie, the path has been painful: Things like updating from version 0.x.0 to version 0.y.0 (specially to version 0.4.0) was particularly terrible…
Continue reading “Unit testing with Jest: Redux + async actions + fetch”

Horizontal scroll animations in React Native – codeburst

  • Horizontal scroll animations in React NativeLink Animated with ScrollView to create a nice navigation UI animation in React NativeWhat we will be buildingRN lets you build a nice and smooth UIWhat you will needReact NativeSimulatorNo third party libraries required :)Creating Screen component with AnimatedFirst, import Animated, Dimensions, ScrollView, StyleSheet, Text, View from “react-native” .
  • Next, create a component that will be treated as a screen or a view.We are using Animated.View here because we are going to animate that wrapper component.That width ofscrollPage style and are important because we are going to interpolate horizontal scrolling values to multiple animation values.
  • In other words, we are going to track where the screen is and animate the screen component based on that value.It’s one of the things that are tricky to explain in words, but it is the key concept to understand for this to work.Basically, we link animations based on the…
  • When the scroll position is at 150, first screen is half way done exiting, and the second screen is half way done entering.Adding animationsSince they are all set up, it is time to write the animations.
  • You would have to write a different inputRange since FlatList removes items that scroll way off screen.I think this is pretty neat UI animation that’s pretty simple to use.

That width ofscrollPage style and transitionAnimation(props.index) are important because we are going to interpolate horizontal scrolling values to multiple animation values. In other words, we are…
Continue reading “Horizontal scroll animations in React Native – codeburst”

JavaScript ES 2017: Learn Async/Await by Example – codeburst

  • Consider the below code:function doubleAfter2Seconds(x) { return new Promise(resolve = { setTimeout(() = { resolve(x * 2); }, 2000); });}In this code we have a function called doubleAfter2Seconds.
  • Here’s what the boilerplate code looks like:function addPromise(x){ return new Promise(resolve = { // Code goes here… // resolve() });}Awesome.
  • In this example we should be returning x + 2*a + 2*b + 2*c. Here’s the code:function addPromise(x){ return new Promise(resolve = { = { = { = { resolve(x + a + b + c); }) }) }) });}Lets walk through the code again, line by line.First, we create…
  • Here’s what that looks like:async function addAsync(x) { // code here…}Now that you’ve created an async function, we can make use of the await keyword which will pause our code until the Promise has resolved.
  • Here’s how easy that is:async function addAsync(x) { const a = await doubleAfter2Seconds(10); const b = await doubleAfter2Seconds(20); const c = await doubleAfter2Seconds(30); return x + a + b + c;}And here’s the full code:As you can see, we’re still making use of the same doubleAfter2Seconds function.

ES 2017 introduced Asynchronous functions. Async functions are essentially a cleaner way to work with asynchronous code in JavaScript. In order to understand exactly what these are, and how they work…
Continue reading “JavaScript ES 2017: Learn Async/Await by Example – codeburst”

The best front-end hacking cheatsheets — all in one place.

  • The best front-end hacking cheatsheets — all in one place.It’s rather impossible to remember all the APIs by heart.
  • This is when cheatsheets jump in!
  • Here are the best front-end cheatsheets I’ve gathered.

The best front-end hacking cheatsheets — all in one place. It’s rather impossible to remember all the APIs by heart. This is when cheatsheets jump in! Here are the best front-end cheatsheets I’ve…
Continue reading “The best front-end hacking cheatsheets — all in one place.”

Upgrading to Flow 0.53.0 and Beyond – William Candillon – Medium

Upgrading to Flow 0.53.0 and Beyond  #react #reactnative #flow #flowtype #reactjs #reactjs

  • How hard could it be?First Step: flow-upgradeReact support in flow v0.53.0 has dramatically improved and as described in this story, there is a utility tool that will automatically migrate your code base: flow-upgrade.
  • Before you do those, please take five to ten minutes to read the flow documentation about its support for React.
  • It was also required to migrate component properties defined using interface with type instead.Second Step: flow-result-checkerWhen running flow with version 0.53.0 and above, you will notice that a lot of node modules throw type errors.
  • For instance, they might be written using an older version of flow as the one you are using.
  • You are not responsible for these errors but you cannot simply ignore in your flow config file.Type errors you are not responsible forThere are two packages available that will filter flow errors from node_modules: flow-result-checker and flow-error-suppressor.

In the past twenty-four hours, my feelings towards flow went from frustration to love. And apparently, I wasn’t alone. If you are experiencing the same rollercoaster as we did, below are a few…
Continue reading “Upgrading to Flow 0.53.0 and Beyond – William Candillon – Medium”

Front-end Developer Survey 2017

  • My first question is what frameworks are people using at work vs for their personal projects.
  • From the poll, it seems that slightly more organizations use Angular over React at work.
  • However, people seem to prefer React over Angular for their personal projects.
  • The survey also showed that most people are happy with their current framework and not wanting to upgrade; but those that did want to upgrade choose React over the alternatives.
  • The data shows that the big driver is Angular with only a mediocre number of projects in React using it.

For the past couple of months, I have been talking to people and asking myself a couple of questions in regard to the state of front-end development today. I figured what better way than to create a survey and see if we can’t make some sense out of the current state of things in the community. We had a amazing number (~890) of people who took a minute out of their day and answered these questions so a huge thank you to those who participated!
Continue reading “Front-end Developer Survey 2017”

So @iamraphson built an amazing ReactJS Library for @theflutterwave Rave, you can check it out at .

  • Why not share the link for this repository on Twitter or Any Social Media?
  • Don’t forget to follow me on twitter!

This is a reactJS library for implementing rave payment gateway
Continue reading “So @iamraphson built an amazing ReactJS Library for @theflutterwave Rave, you can check it out at .”