1626572760
If you want to learn more about ReactJS with Hooks, Redux, Mobx and React Router V4 you can check out my course I offer support and continuous updating of these course as these technology changes and also it is the best way to support my channel
Enroll In this Course
https://www.shoaibbhimani.com/courses.html
I have create react tutorial long time ago I think it was one of earliest video on react in Hindi and Urdu since then react have come a long way and many new syntax and better way of doing things have emerged so I thought let create react tutorial for complete beginners. In this video you will learn how to build Blog App with React, Axios, React Testing library and Chakra UI
Subscribe to this channel
https://www.youtube.com/channel/UCTbyx-u9f1U8tFxbR_0CHFg?view_as=subscriber?sub_confirmation=1
Learn Javascript from Scratch | Hindi / Urdu: https://www.youtube.com/playlist?list=PLxnSeqQVewBPKOOS6xuMFFPW0BQoEk8k5
https://www.udemy.com/course/learn-reactjs-fundamentals-in-hindi-urdu/
Visit: http://shoaibbhimani.com
Want to Improve your Javascript Skills check out this book
https://amzn.to/2WiCPpv
Microphones I use
Mic Filter which good to remote noise while recording
https://amzn.to/2vWs952
Mic Stand
http://amzn.to/2fIJ5Rn
Webcam I use
https://amzn.to/2JAo61L
Laptop I use
https://amzn.to/2vWNKKG
Follow Me on
Udemy: https://www.udemy.com/user/shoaib-bhimani/
Twitter: https://twitter.com/shoaibbhimani
Github https://github.com/shoaibbhimani
About Me:
I am a Software Engineer from Mumbai (India). I Create High Quality video tutorials on cutting edge technology like React, Redux, Mobx, JQuery, React Router, Ecmascript, Javascript and other latest technologies
#react
1598839687
If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?
In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.
Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.
React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.
Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.
Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.
The popularity of React Native comes from its advantages. Some of its advantages are as follows:
Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.
React Native is very close to native. Consider the following aspects as described on the React Native website:
Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.
#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native
1599639298
Testing is complicated. I’ve certainly never been good at it. For the longest time, I’ve only been focused on basic function input-output unit tests. Why? Because they were easy — you didn’t need to render HTML, you didn’t need to query DOM elements, you didn’t need to interact with said DOM elements. But of course, React component testing is a necessity for any mature codebase. And it finally came time for me to sit down and figure it out.
That’s when I discovered React Testing Library. And suddenly, everything seemingly became much simpler. All the complexities that I’ve encountered, but not understood, that made me put off React component testing disappeared. Hopefully, the same will happen for you.
#react-testing-library #unit-testing #react #jest #interaction-testing
1597168800
Let’s step up our testing game with two useful libraries that lend themselves excellently to a TDD approach.
Whenever I want to try out something React-related, I use the library create-react-app. It gives you a ready-to-work-with basic React application with no configuration needed. Recent versions also come bundled with React Testing Library, so if you use the latest create-react-app, you can start using React Testing Library straight away. If not — install @testing-library/react and @testing-library/jest-dom in your existing React application.
I am going to implement the following functionality: a simple recipe list with a search function. It will look something like this to a user in a mobile browser:
Image credits: Burger Photo by Robin Stickel on Unsplash, French Toast Photo by Joseph Gonzalez on Unsplash, Salmon Photo by Casey Lee on Unsplash
I want to use a TDD approach, so let’s start with a failing test. At this point, there is no component yet, so of course whatever test we write is going to fail. But let’s start small; I want a component named ‘Recipes’ that renders the expected heading text. Here is my test for that expectation:
import React from 'react';
import { render, screen } from '@testing-library/react';
test('renders the heading', () => {
render(<Recipes />);
expect(screen.getByRole('heading')).toHaveTextContent('Recipe Finder');
});
React testing library exports a render method, which will render a component and all of its child components. It also exports a screen object, holding a number of queries we can use to select different elements in our rendered component (and its child components too). The **getByRole **query lets me select the heading element and make an assertion on its text content.
Why select the heading element by its role and not for example a CSS class? The guiding principle of React Testing Library is “The more your tests resemble the way your software is used, the more confidence they can give you.” Therefore, we want to write our tests as close as possible to how the ultimate tester — the end user — will be using the application. Users don’t see CSS classes or data attributes; they interact with text, label text and semantic elements and roles. Using queries such as getByRole also encourages us to write accessible code, since these selectors are available to everyone, including users of screen readers.
Our first test fails as expected.** Recipes is not defined.** But this is the first step in TDD — a failing test. Now, let’s make it pass by writing the simplest possible component with the correct heading and then importing it in our test file. Now, let’s re-run the test. It passes!
import React from 'react';
const Recipes = () => {
return (
<div>
<h1>Recipe Finder</h1>
</div>
)
};
export default Recipes;
Using further queries, we can make similar expectations for the input element and the “Find” button. The button also has a role, but for the input field, I will use the getByPlaceholderText query, since that is probably the closest query to how the user would find it on the page.
Start with a failing test…
import React from 'react';
import { render, screen } from '@testing-library/react';
import Recipes from './Recipes';
test('renders the heading, input field and button', () => {
render(<Recipes />);
expect(screen.getByRole('heading')).toHaveTextContent('Recipe Finder');
expect(screen.getByPlaceholderText('Enter an ingredient to find recipes...'))
.toBeInTheDocument();
expect(screen.getByRole('button')).toHaveTextContent('Find');
});
… and implement the changes necessary to make it pass:
import React from 'react';
const Recipes = () => {
return (
<div>
<h1>Recipe Finder</h1>
<form>
<input
type="text"
name="ingredient"
placeholder="Enter an ingredient to find recipes..."
/>
<button type="submit">Find</button>
</form>
</div>
)
};
export default Recipes;
This way, we know what we expect from our code and more importantly — we will know if we break any functionality if the previously passing tests suddenly fail.
An important step in TDD is the refactor step, where we improve our code to for example make it easier to read, become more efficient and remove any duplication. The test should still pass after we refactor.
When the application first renders, I want to display a list of all my recipes, just like in the visual design above. This requires some kind of communication with an API. We are going to use Mock Service Worker to mock the HTTP-requests, so that we can control the response data. Install Mock Service Worker with npm like this:
npm install msw --save-dev
With Mock Service Worker, we are not mocking a specific module (unlike if we were to use Jest.mock), which means that it makes no difference if I use fetch or a third-party library such as axios to get the data. This makes it incredibly flexible. Let’s add the following imports to our test file:
import { rest } from 'msw';
import { setupServer } from 'msw/node';
Here is how I set up mocking a call to the recipe list endpoint:
import React from 'react';
import { render, screen } from '@testing-library/react';
import Recipes from './Recipes';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
const allRecipes = [
{ id: 1, title: 'Burger' },
{ id: 2, title: 'French toast' },
{ id: 3, title: 'Salmon' }
];
const server = setupServer(
rest.get('/api/recipes', (req, res, ctx) => {
return res(ctx.json({ recipes: allRecipes }));
})
);
beforeAll(() => server.listen());
afterAll(() => server.close());
If you have worked with NodeJS and Express, the syntax looks very familiar. GET requests to ‘/api/recipes’ will respond with JSON containing the allRecipes array, just like a real API would. These two lines make sure the server starts listening (intercepting) before the tests run and closes its connection when the tests in this file have finished running:
beforeAll(() => server.listen());
afterAll(() => server.close());
#tdd #react-testing-library #react #test-driven-development #testing
1603955580
Like most, when I first started using Testing Library, I used Fire Event to test component interactions. After all, this API shipped with the library itself and was used in the test examples in the documentation. But I soon discovered that Fire Event had serious limitations. I would try clicking something and the expected effect did not happen. Why?
To understand this issue, we need to better understand browser events. When a user clicks something in their browser, multiple events are triggered — mouseDown
, mouseUp
, click
, and focus
. Similarly, when typing something, the keyDown
, keyUp
, and keyPress
events all trigger! Because a single user interaction could trigger multiple events, developers have multiple options for implementation. This is where I ran into my issue.
Fire Event, unfortunately, requires you to use the method for the corresponding event handler to trigger. If an element has an onClick
event handler, I have to use fireEvent.click
; if an element has an onMouseDown
event handler, I have to use fireEvent.mouseDown
. In other words, I need to know the exact implementation of the event handler to successfully use fireEvent
.
#react #jest #integration-testing #unit-testing #react-testing-library #react native
1599224220
Unit testing, and in our case, testing components, is a key element of any scalable and maintainable project. That truism is even more obvious now in the age of independent and shareable components. When sharing components between projects, testing serves as a way to both validate that a component behaves as expected and that it is independent and reusable (otherwise it would show to be very difficult to test).
React components shared from different projects to Bit.dev (using Bit)
When it comes to testing React components, one of the most popular testing frameworks is Enzyme. But if you start a brand new project using thecreate-react-app
command-line tool, what you would see is the React Testing Library (RTL). It’s not just another testing utility. This library promotes a different way of testing React components. If we take a closer look, it makes it much easier to test these components.
Let’s have a look a the challenges with the current testing approach using a practical example.
Just imagine, you write your unit tests based on CSS class selectors. In a later stage, a refactoring happens, and bam !!! all your tests are failing now.
The same thing happens when you depend on props and state in your tests. Here the tests are more tightly coupled with implementation details. Hence, it becomes less maintainable.
#react-testing-library #web-development #react #javascript #front-end-development