<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sahara Banu</title>
    <description>The latest articles on DEV Community by Sahara Banu (@saharabanu).</description>
    <link>https://dev.to/saharabanu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F821165%2Fdf18f504-b2cc-41fa-9648-254416b1f742.png</url>
      <title>DEV Community: Sahara Banu</title>
      <link>https://dev.to/saharabanu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saharabanu"/>
    <language>en</language>
    <item>
      <title>Unit Tesing with Jest in React Typescript</title>
      <dc:creator>Sahara Banu</dc:creator>
      <pubDate>Fri, 04 Mar 2022 07:14:36 +0000</pubDate>
      <link>https://dev.to/saharabanu/unit-tesing-with-jest-in-react-typescript-3anb</link>
      <guid>https://dev.to/saharabanu/unit-tesing-with-jest-in-react-typescript-3anb</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Unit Testing?&lt;/strong&gt;&lt;br&gt;
A unit test is a way of testing unit where a section of code or components are tested. Its' purpose is to test each unit or function. A unit is the smallest testable part of an application. It mainly has one or a few inputs and produces a single output.Unit Testing is done during the development of an application by the developers.&lt;/p&gt;

&lt;p&gt;Some benefits of Unit testing are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unit test tend to be fast, providing quick feedback to engineers.&lt;/li&gt;
&lt;li&gt;Good unit tests serve as project documentation&lt;/li&gt;
&lt;li&gt;Unit testing makes refactoring possible.&lt;/li&gt;
&lt;li&gt;Unit tests help to fix bugs early in the development cycle and save costs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How does Typescript Unit Testing differ from JavaScript Unit Testing?&lt;/strong&gt;&lt;br&gt;
JavaScript is programming language and Typescript is superset of javaScript.TypeScript unit testing differs from regular JavaScript unit testing in at least two ways. First of all, by leveraging static typing, a whole class of errors becomes impossible. So, you probably end up writing fewer tests. Also, TypeScript unit testing requires you to install some additional packages, which are needed to make the unit testing tools work with non-standard JavaScript syntax.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Write a Unit Testing in our react Typescript Project&lt;/strong&gt;&lt;br&gt;
At first, We have to create a react app with typescript.And then, We need  some dependencies. One of them is Jest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JEST:&lt;/strong&gt;&lt;br&gt;
Jest is a universal testing platform, with the ability to adapt to any JavaScript library or framework. It is used by many companies.Jest provides the ability to perform these tasks via functions like beforeAll, beforeEach, afterAll, and afterEach.&lt;/p&gt;

&lt;p&gt;We have to follow, This pattern(Arrrage,Act,Asserts) is a common way of writing unit tests for a method under test.&lt;br&gt;
The Arrange section of a unit test method initializes objects and sets the value of the data that is passed to the method under test.&lt;br&gt;
The Act section invokes the method under test with the arranged parameters.&lt;br&gt;
The Assert section verifies that the action of the method under test behaves as expected. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unit Testing Component Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If we want to add unit testing in our React TypeScript.Normally we have to follow 4 steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. First Step Install&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;*npx create-react-app my-app-name --template typescript&lt;br&gt;
or&lt;br&gt;
yarn create react-app my-app-name --template typescript&lt;/p&gt;

&lt;p&gt;and then&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;npm install --save-dev jest @types/jest &lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-typescript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Second Step Add Babel Preset&lt;/strong&gt;&lt;br&gt;
Since, we have installed babel preset, so we  have to add this in our project. We can use jest.config.js without babel.&lt;/p&gt;

&lt;p&gt;We have to create a file &lt;em&gt;babel.config.js&lt;/em&gt; near by package.json and add this and save.&lt;/p&gt;

&lt;p&gt;module.exports={&lt;br&gt;
    "presets": ["&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-env", "&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-react", "&lt;a class="mentioned-user" href="https://dev.to/babel"&gt;@babel&lt;/a&gt;/preset-typescript"],&lt;br&gt;
    "plugins": []&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;and we have also to add in package.json&lt;br&gt;&lt;br&gt;
"scripts": {&lt;br&gt;
    "start": "react-scripts start",&lt;br&gt;
    "build": "react-scripts build",&lt;br&gt;
    &lt;strong&gt;"test": "jest",&lt;/strong&gt;&lt;br&gt;
    "eject": "react-scripts eject"&lt;br&gt;
  },&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Third Step Add Test&lt;/strong&gt;&lt;br&gt;
We have to test one section of code. So we can create a file that means if we want to test this component, and we will create there a file like(login.test.tsx) or can do in App.test.tsx .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F46rvtpezh8s19jl9wgst.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F46rvtpezh8s19jl9wgst.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;last Step Test&lt;/strong&gt;
In Visual Code terminal, we can run this command. npm test
If everything is ok, then result will be shown pass.If in any case,result gives fail, then we will try to fix this.For solving this bug, we can follow Stackoverflow website .It is really helpfull for any bug fixing. And we can serach Debug unit testing in Vscode in react app.
I have done a test and finally complete it.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdzb4i90wm9wkcq4hyubd.PNG" alt="Image description"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br&gt;
It is my first practise in unit testing.I have failed many times and finally I have succeeded.So, Please comment me how can I improve my lackings.I am still learning and want to know more About Unit Testing.Really It's very interesting. I enjoy it when I practise it.&lt;br&gt;
Overall, I think this pattern can help you write tests faster and with less repetition.&lt;/p&gt;

</description>
      <category>unit</category>
      <category>testing</category>
      <category>react</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Typescript and tailwind css</title>
      <dc:creator>Sahara Banu</dc:creator>
      <pubDate>Thu, 24 Feb 2022 13:10:38 +0000</pubDate>
      <link>https://dev.to/saharabanu/typescript-and-tailwind-css-3ch2</link>
      <guid>https://dev.to/saharabanu/typescript-and-tailwind-css-3ch2</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Typescript?&lt;/strong&gt;&lt;br&gt;
Typescript is a programming language, It is an open source and it is a superset of javascript.It adds optional static typig to hte language. Actually it is designed for the development of large applications na transcompiles to javascript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do I use Typescript in large application?&lt;/strong&gt;&lt;br&gt;
At first , I will say, typescript simplifies to javascript.It helps us to write clean and properly structured code.It makes code easier to read and understand. It is very smooth, flexible and with almost no overhead rather than migration process from JavaScript.&lt;br&gt;
&lt;strong&gt;It has some benefits; like:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;WE can avoid errors like 'undefined'is not a function.
*WE can directly see our coding errors in our visual studio code.It is easier to refactor code without breaking it significantly.&lt;/li&gt;
&lt;li&gt;Typescript upholds interfaces.&lt;/li&gt;
&lt;li&gt;TypeScript has better documentation for APIs which is in a state of harmony with a source code. A few organizations report a decrease in bugs when they change to TypeScript.&lt;/li&gt;
&lt;li&gt;Typescript runs in any program or javascript.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How to install typescript in our project?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&amp;lt;&amp;gt; If we want to set typescript with HTML , then we will install only this&lt;br&gt;
npm i typescript&lt;br&gt;
&amp;lt;&amp;gt; If we set want to  typescript with React Framework ,then&lt;br&gt;
npx create-react-app my-app --template typescript&lt;br&gt;
or &lt;/p&gt;

&lt;p&gt;yarn create react-app my-app --template typescript&lt;br&gt;
And If we want ro set typescript with previous any project,then we can follow this link;&lt;/p&gt;

&lt;p&gt;npm install --save typescript @types/node @types/react @types/react-dom @types/jest&lt;/p&gt;

&lt;p&gt;or&lt;br&gt;
yarn add typescript @types/node @types/react @types/react-dom @types/jest&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Typescript&lt;/strong&gt;&lt;br&gt;
The Typescript has some common built-in data types which are given below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number *String * boolean * null *undefined *enum *void * never * any *Array *unknown * any.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can declare these types in variable.If we don't declare type with variable, then en error has occured. so, we must declare type with variable. Example;&lt;br&gt;
 let countryName:string = "Bangladesh";&lt;br&gt;
let isBeautiful:boolean=true;&lt;br&gt;
let age:number = 25; and etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interface of Typescript&lt;/strong&gt;&lt;br&gt;
Interfaces are able to describe the widw range of shapes that JavaScript objects can take. When we declare an object ,then we need interface or type to do our code neat and clean.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NFhw-ILY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wotlc7g0aam8y2ukp47v.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NFhw-ILY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wotlc7g0aam8y2ukp47v.PNG" alt="Image description" width="438" height="146"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We also declare in this system. But we always try to declare in  interface rather than type.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lunm1Fvv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwmkz3o7yeh6wbfxzkyn.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lunm1Fvv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwmkz3o7yeh6wbfxzkyn.PNG" alt="Image description" width="262" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have explored typescript and have done some projects using typescript and I am still learning typescript to do better performance. From this, I shared some code example of my Todo App.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7obomNuj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4owkvwq2op0pq3s0te3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7obomNuj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4owkvwq2op0pq3s0te3.PNG" alt="Image description" width="681" height="588"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Apf4FUeu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fs5gl6o41p9wtouqlf0g.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Apf4FUeu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fs5gl6o41p9wtouqlf0g.PNG" alt="Image description" width="880" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At last, we use typescript rather than JavaScript in our project because typescript is a superset of javascript.We can code both javascript and typescript in typescript. We can declare what types of my code. We can solve error directly in our code.The code is easier to refactor.It supports third-parties package.TypeScript performs type checks at compilation time, it helps prevent runtime errors before the application is even started. Those benefits increase time for writing Typescript code with higher requirements for all the developer's qualification. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tailwind Css&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Tailwind CSS?&lt;/strong&gt;&lt;br&gt;
 Tailwind css is utility-first css framework.It is used for rapidly building custom user interface(UI). It is a highly customizable, low-level css framework that gives us more flexibility designs without boring opinionated styles that we have to fight to override. Personally, I like tailwind css framework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to install tailwind css in our project?&lt;/strong&gt;&lt;br&gt;
 If we want to set i HTML, tailwind setup is very complex to me but its benefits many. So,we will setup tailwind css installation with  carefully and will move step by step. We must have to read more and more tailwind css documentation and how to install it.&lt;br&gt;
We can follow this link:  &lt;a href="https://tailwindcss.com/docs/installation"&gt;https://tailwindcss.com/docs/installation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2dHIdlW5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rk04sryp9xy44kerdm36.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2dHIdlW5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rk04sryp9xy44kerdm36.PNG" alt="Image description" width="547" height="424"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wwiuR87w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfvl9tj1ve2dufcs8n4d.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wwiuR87w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfvl9tj1ve2dufcs8n4d.PNG" alt="Image description" width="530" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fP24tXqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1m5drnt19lhzntp0unv.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fP24tXqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1m5drnt19lhzntp0unv.PNG" alt="Image description" width="523" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we want to setup tailwind css with react. Then, we can follw this link: &lt;strong&gt;&lt;a href="https://tailwindcss.com/docs/guides/create-react-app"&gt;https://tailwindcss.com/docs/guides/create-react-app&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
or&lt;br&gt;
 we can follow the youtube vedio.&lt;br&gt;
&lt;strong&gt;&lt;a href="https://www.youtube.com/watch?v=YL5deOIXbPc"&gt;https://www.youtube.com/watch?v=YL5deOIXbPc&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have used tailwind css in my react typescript project.There are many free designable components in tailwind css that helps us in many ways for styling in our project.  We can do easily responsive for any devices using tailwind css. Some code of my project;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gs3uimYL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rea1v75rss4e1q3colgp.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gs3uimYL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rea1v75rss4e1q3colgp.PNG" alt="Image description" width="807" height="623"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At last, I can say in this blog.it is very helpful for begginers.We can use tailwind css framework with any frontend framework.Typescript is very popular language and superset of JavaScript. Its' demand is increasing day by day.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>tailwindcss</category>
    </item>
  </channel>
</rss>
