<?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: Behzad Ali Mohammad Zad</title>
    <description>The latest articles on DEV Community by Behzad Ali Mohammad Zad (@behzadam).</description>
    <link>https://dev.to/behzadam</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%2F210066%2F4aa2d54c-7ae6-42cd-bd4b-11278b070a1e.jpg</url>
      <title>DEV Community: Behzad Ali Mohammad Zad</title>
      <link>https://dev.to/behzadam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/behzadam"/>
    <language>en</language>
    <item>
      <title>Illustrated Snapshot Testing</title>
      <dc:creator>Behzad Ali Mohammad Zad</dc:creator>
      <pubDate>Wed, 23 Mar 2022 22:15:17 +0000</pubDate>
      <link>https://dev.to/behzadam/illustrated-snapshot-testing-45h9</link>
      <guid>https://dev.to/behzadam/illustrated-snapshot-testing-45h9</guid>
      <description>&lt;p&gt;First, I want to say that for many cases you don’t need to use snapshot testing. You can find a good article here: &lt;a href="https://www.chakshunyu.com/blog/what-are-proper-use-cases-for-snapshot-testing-react-components/"&gt;What Are Proper Use Cases For Snapshot Testing React Components?&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Second, if you are interested in software quality and testing then it is better to know about tools and concepts although some of them are rarely used.&lt;/p&gt;

&lt;p&gt;Let's take a look at how snapshot testing works ( example is in Jest ):&lt;br&gt;
&lt;code&gt;expect(component).toMatchSnapshot();&lt;/code&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DQjIuDE6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mfoqu1eq93yfc5jr79xn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DQjIuDE6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mfoqu1eq93yfc5jr79xn.png" alt="Image description" width="880" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The process:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rg0gJAZx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x950kgxwfdcy2jc7yzfb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rg0gJAZx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x950kgxwfdcy2jc7yzfb.png" alt="Snapshot testing process" width="880" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sWtVPjs7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pq9aajnyopamokfuwhe8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sWtVPjs7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pq9aajnyopamokfuwhe8.png" alt="Snapshots are code" width="880" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CGKzI-rU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ka17ka3a16uai6wgpnmb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CGKzI-rU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ka17ka3a16uai6wgpnmb.png" alt="Nextjs snapshot testing" width="410" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some tips:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visual regression testing tools take screenshots of web pages and compare the resulting images pixel by pixel.&lt;/li&gt;
&lt;li&gt;With Snapshot testing values are serialized, stored within text files, and compared using a diff algorithm and this is why it's made.&lt;/li&gt;
&lt;li&gt;Commit snapshots and review them as part of your regular code review process.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j-KYXfwC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aoncc6g46lj38rnpjw0p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j-KYXfwC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aoncc6g46lj38rnpjw0p.png" alt="Snapshot testing Visual regression testing" width="880" height="644"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://jestjs.io/docs/snapshot-testing"&gt;Jest Snapshot Testing&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=sCbGfi40IWk"&gt;Youtube&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/@luisvieira_gmr/snapshot-testing-react-components-with-jest-3455d73932a4"&gt;Snapshot testing React components with Jest&lt;/a&gt;&lt;/p&gt;

</description>
      <category>testing</category>
      <category>react</category>
      <category>productivity</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Illustrated Typescript: is keyword</title>
      <dc:creator>Behzad Ali Mohammad Zad</dc:creator>
      <pubDate>Tue, 15 Mar 2022 13:38:42 +0000</pubDate>
      <link>https://dev.to/behzadam/illustrated-typescript-is-keyword-5c9k</link>
      <guid>https://dev.to/behzadam/illustrated-typescript-is-keyword-5c9k</guid>
      <description>&lt;p&gt;This is my first article and I'm trying to visualize my articles and called it &lt;strong&gt;Illustrated&lt;/strong&gt; series. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I hope the attached  photos are really better than 1000 words for you.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What is &lt;code&gt;is&lt;/code&gt; keyword in Typescript? Let's see:&lt;/p&gt;

&lt;p&gt;Imagine, you want to publish a lib that contains some utility functions like below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3jrI5MCO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d3yv4sdm9a1xtwyqi934.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3jrI5MCO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d3yv4sdm9a1xtwyqi934.gif" alt="User-Defined Type Guards" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We do not have any access to &lt;code&gt;Date&lt;/code&gt; methods because the function returns a &lt;code&gt;boolean&lt;/code&gt; and why we should access to &lt;code&gt;Date&lt;/code&gt; methods?&lt;/p&gt;

&lt;p&gt;Typescript performs &lt;strong&gt;User-Defined Type Guards&lt;/strong&gt; and it would be better if we performed a type checked:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E8jNixhZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cle9vyeplflqhcmzklal.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E8jNixhZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cle9vyeplflqhcmzklal.gif" alt="User-Defined Type Guards" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the &lt;code&gt;isDate&lt;/code&gt; function returns true, TypeScript will narrow the type to &lt;code&gt;Date&lt;/code&gt; in &lt;code&gt;if&lt;/code&gt; block and now, we have access to &lt;code&gt;Date&lt;/code&gt; methods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABDAzgEQIZQKYAoBuGANiNgFyIZgCeAlBYSdsiopjogN4CwAUIogBO2KCEFJGpZGBRQqEbHGBss2ANx8Avnz4B6AFSJwEOAFtT2MFEpgAJoiiDqfUJFgIW7PJPI26FACM4OCJsKh5+IRExCWIpGBk5SEVlLw1ebV59fV0dXhNElgAhbGA4YUQAXkRcBIAHECgKWUEEgHNEAB8VHHpEIJCwpEqAPi4+ARhgWvRVWrAGqFpaccjJhcaAOgnETIFhUXFEYGIUdS08vKA"&gt;Try it online.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a good day/night with Typescript. &lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>vue</category>
      <category>node</category>
    </item>
  </channel>
</rss>
