<?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: YashasaveeKesarwani99</title>
    <description>The latest articles on DEV Community by YashasaveeKesarwani99 (@yashasaveekesarwani99).</description>
    <link>https://dev.to/yashasaveekesarwani99</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%2F531157%2F78dfacb8-7812-4acf-96c7-5c12ee11db8a.png</url>
      <title>DEV Community: YashasaveeKesarwani99</title>
      <link>https://dev.to/yashasaveekesarwani99</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yashasaveekesarwani99"/>
    <language>en</language>
    <item>
      <title>To do list app with react typescript and react testing library</title>
      <dc:creator>YashasaveeKesarwani99</dc:creator>
      <pubDate>Thu, 13 Jan 2022 18:26:44 +0000</pubDate>
      <link>https://dev.to/yashasaveekesarwani99/to-do-list-app-with-react-typescript-and-react-testing-library-4a22</link>
      <guid>https://dev.to/yashasaveekesarwani99/to-do-list-app-with-react-typescript-and-react-testing-library-4a22</guid>
      <description>&lt;h2&gt;
  
  
  Using typescript and testing code with react testing library
&lt;/h2&gt;

&lt;p&gt;Typescript really makes it easy for developers to know the type of variables and return type of the functions which are in play.&lt;/p&gt;

&lt;p&gt;I have used hooks for managing states, one can mention the type of state they are defining which makes its type unchangeable resulting in lesser discrepancy issues.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const [task,setTask] = useState&amp;lt;string&amp;gt;("");
  const [tasks,setTasks] = useState&amp;lt;Array&amp;lt;string&amp;gt;&amp;gt;([])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The type of props should be defined before using them in the children component which can be done using &lt;code&gt;type&lt;/code&gt; or &lt;code&gt;interface&lt;/code&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type props = {
    setTask:React.Dispatch&amp;lt;React.SetStateAction&amp;lt;string&amp;gt;&amp;gt;
    tasks:string[] 
    setTasks:React.Dispatch&amp;lt;React.SetStateAction&amp;lt;string[]&amp;gt;&amp;gt;
    task:string
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For testing purpose I've used react testing library to do simple unit and integration testing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mockSetTask = jest.fn()
const mockSetTasks = jest.fn()

var task:string
var tasks:string[] = []

it('gets input from input component',  ()=&amp;gt;{
        render(&amp;lt;Input  setTask={mockSetTask} setTasks={mockSetTasks} tasks={tasks} task={task}/&amp;gt;)
        const ele = screen.getByPlaceholderText("Enter Task") as HTMLInputElement

        fireEvent.change(ele,{target:{value:'Go To Gym'}})
        expect(ele.value).toBe('Go To Gym')
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Github Repo : &lt;a href="https://github.com/YashasaveeKesarwani99/todolist"&gt;To do list app&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
      <category>testing</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
