Learning Redux-Saga #javascript #reactjs #redux #redux-saga

Learning Redux-Saga  #javascript #reactjs #redux #redux-saga

  • Redux-saga is a Redux middleware to handle side effects, mainly the asynchronous actions which change the state.
  • A saga is a generator function that can run asynchronous actions indefinitely like a thread in the application.
  • On the other hand, Redux-saga uses the generators which can pause, resume, and interact with the asynchronous actions by using generators.
  • Each of the following functions will return a saga effect which is an object containing instructions of what/how the action should be executed by the saga middleware.
  • takeEvery – – Resolve the effect with the result of each time that the action is received.

Redux-saga is a Redux middleware to handle side effects, mainly the asynchronous actions which change the state. A saga is a generator function that can run asynchronous actions indefinitely like a thread in the application.
Continue reading “Learning Redux-Saga #javascript #reactjs #redux #redux-saga”

Learning Redux-Saga #javascript #reactjs #redux #redux-saga

Learning Redux-Saga  #javascript #reactjs #redux #redux-saga

  • Redux-saga is a Redux middleware to handle side effects, mainly the asynchronous actions which change the state.
  • A saga is a generator function that can run asynchronous actions indefinitely like a thread in the application.
  • On the other hand, Redux-saga uses the generators which can pause, resume, and interact with the asynchronous actions by using generators.
  • Each of the following functions will return a saga effect which is an object containing instructions of what/how the action should be executed by the saga middleware.
  • takeEvery – – Resolve the effect with the result of each time that the action is received.

Redux-saga is a Redux middleware to handle side effects, mainly the asynchronous actions which change the state. A saga is a generator function that can run asynchronous actions indefinitely like a thread in the application.
Continue reading “Learning Redux-Saga #javascript #reactjs #redux #redux-saga”

Mocking API responses with React Apollo – Carlos Martinez – Medium

  • Mocking API responses with React ApolloApollo Client and the GraphQL tools that have been made open source within the last years are pretty awesome, the community that is being builded around them is great.
  • However, as with every new technology, there are a lot of things that need to mature and improve.Documentation on testing is definitely one of the bits that needs a lot of improvements, it isn’t clear what to do, and I personally found myself digging into the source code to understand what to do.One of the problems I faced was that I wanted to use mock responses when testing my app components, and there are at least two ways of doing this:The first way is to use graphql-tools.
  • From their docs:This package allows you to use the GraphQL schema language to build your GraphQL.js schema, and also includes useful schema tools like per-type mocking.You can use this library together with a custom MockNetworkInterface to return mocked responses to your components:const { mockServer } = require(“graphql-tools”);const { print } = MockNetworkInterface { constructor(schema, mocks = {}) { if (!
  • schema) { throw new Error(‘Cannot create Mock Api without specifying a schema’); } this.mockServer = mockServer(schema, mocks); } query(request) { return request.variables); }}This is nice, and very flexible, with graphql-tools you can do pretty much whatever you do in your actual API.What I didn’t like about this approach is that you need your schema in sync with the schema defined in your API (you can do this making an instrospection query to your backend), I also found this approach overcomplicates things unnecessarily.The second (and simpler) approach I found was to use the mockNetworkInterface class, this class is defined in react-apollo/test-utils, you can have a peek on it here.To use it, you first need to define some Mock Requests (these requests need to be exactly the same your components will make):const GraphQLMocks = [ { request: { query: UserProfileQuery, variables: {} }, result: { data: { current_user: { id: 1, first_name: ‘Foo’, last_name: ‘Bar’, email: ‘foo@example.com’ } } } }];The UserProfileQuery is exported from your component:export const UserProfileQuery = gql` query userProfile { current_user { id first_name last_name email } }`;And this is how you use it to setup your tests:import { mockNetworkInterface } from ApolloClient from ‘apollo-client’;import { ApolloProvider } from ‘react-apollo’;import { mount } from ‘enzyme’;import App from ‘.
  • /App.js’;import React from ‘react’;const setupTests = () = { const networkInterface = // or mocks); const client = new ApolloClient({ networkInterface, addTypename: false }); const wrapper = mount( ApolloProvider client={client} App / /ApolloProvider ); return { wrapper };};It is important that you pass addTypename: false to ApolloClient, otherwise you would have to include a __typename field in all your mocks and queries.Now any queries your components make will be handled by your mocked responses, you have full control of what you want to return.And that’s it!

Apollo Client and the GraphQL tools that have been made open source within the last years are pretty awesome, the community that is being builded around them is great. However, as with every new…
Continue reading “Mocking API responses with React Apollo – Carlos Martinez – Medium”

TDD? Waste of time! – Reactive Conf

Doing TDD today is a waste of time in 99% of cases:  #ReactJS #JavaScript

  • Trying out your code with various inputs is the testing every single one of us is familiar with.Writing automatic tests is a waste of time in 99% of cases.Yes, automatic tests have following benefits in comparison with “testing by hand”:You write the test once and can run it million times.
  • If your code changes due to code review or refactoring, you can just re-run it.It can serve as a record for code review that you thought of all the corner cases.When making a new feature, they serve as proof you didn’t break the rest of the system.Tests come at a significant cost as TDD programmers spend as much as half of their time writing tests.That may be acceptable if we run the test a hundred times.
  • TDD encourages, however, writing mostly unit tests.Testing pyramidWhen we refactor the unit, we usually intentionally change its contract and tests fail as expected, which is useless.Failed tests are useful only if they fail unexpectedly.If we take the real cost of automatic testing into account, the well-known ice cream cone anti-pattern doesn’t look like an anti-pattern anymore.Ice cream cone anti-patternMost bugs are caused by wrong interaction between units rather than faulty units.
  • You can’t commit a manual test to a repo, you can’t easily verify it on a code review.Could we make writing tests as simple as testing manually?Cool things are happening in the testing field right now.
  • I hope he’s got some ideas how to finally make automatic tests cheap to write and maintain!Rogelio GuzmanIf you are as excited about Jest Snapshots as we are, snap up your ticket today!

Test-driven development is extremely costly. Yet, it is the religion of our profession, encouraged even when the benefit-cost ratio is low. Should we stop doing it? Can we make testing cheaper…
Continue reading “TDD? Waste of time! – Reactive Conf”

TDD? Waste of time! – ReactiveConf – Medium

TDD? Waste of time!  #javascript #react #testing #reactjs

  • Trying out your code with various inputs is the testing every single one of us is familiar with.Writing automatic tests is a waste of time in 99% of cases.Yes, automatic tests have following benefits in comparison with “testing by hand”:You write the test once and can run it million times.
  • If your code changes due to code review or refactoring, you can just re-run it.It can serve as a record for code review that you thought of all the corner cases.When making a new feature, they serve as proof you didn’t break the rest of the system.Tests come at a significant cost as TDD programmers spend as much as half of their time writing tests.That may be acceptable if we run the test a hundred times.
  • TDD encourages, however, writing mostly unit tests.Testing pyramidWhen we refactor the unit, we usually intentionally change its contract and tests fail as expected, which is useless.Failed tests are useful only if they fail unexpectedly.If we take the real cost of automatic testing into account, the well-known ice cream cone anti-pattern doesn’t look like an anti-pattern anymore.Ice cream cone anti-patternMost bugs are caused by wrong interaction between units rather than faulty units.
  • You can’t commit a manual test to a repo, you can’t easily verify it on a code review.Could we make writing tests as simple as testing manually?Cool things are happening in the testing field right now.
  • I hope he’s got some ideas how to finally make automatic tests cheap to write and maintain!Rogelio GuzmanIf you are as excited about Jest Snapshots as we are, snap up your ticket today!

Test-driven development is extremely costly. Yet, it is the religion of our profession, encouraged even when the benefit-cost ratio is low. Should we stop doing it? Can we make testing cheaper…
Continue reading “TDD? Waste of time! – ReactiveConf – Medium”

Build React Native Apps for Android and iOS Coupon Save 40 %

Build React Native Apps for Android and iOS
☞

  • Lifetime learning and support – React Native is new and still maturing this course will continue to grow and get updates as the language evolves.
  • The course will teach you React Native , get you started in building cross platform mobile apps for iOS and Android that deliver a native experience, provide you with hands-on experience and develop your skills.
  • You will build cross platform mobile apps for Android and iOS in React Native !
  • The course is designed to be a one stop course covering both React Native for Android and iOS .
  • React Native enables you to build iOS and Android mobile apps and benefit from code reuse cross platform.

Coupon 100 10 15 75 create programs in React Native and develop apps for iOS and Android devices
Continue reading “Build React Native Apps for Android and iOS Coupon Save 40 %”

Building a New React Site… (part 259)

  • with that, you need to make sure you understand what TDD is first before you can crawl and practice it.
  • Some people ask: “When is TDD relevant”.
  • Building a New React Site via Outside-in TDD (part 259)
  • So at times I’d like to share with you my experience test driving that

Read the full article, click here.


@DaveSchinkel: “wanna watch me code? Live stream recording from yesterday #reactjs #programming”


This video is about Building a New React Site via Outside-in TDD, created by dschinkel, who showed impressive coding skills in JavaScript


Building a New React Site… (part 259)