<?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: Seyram Ofori</title>
    <description>The latest articles on DEV Community by Seyram Ofori (@seyofori).</description>
    <link>https://dev.to/seyofori</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%2F990682%2F86df828e-9d66-49cf-911d-1d8fc1486855.jpeg</url>
      <title>DEV Community: Seyram Ofori</title>
      <link>https://dev.to/seyofori</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/seyofori"/>
    <language>en</language>
    <item>
      <title>TIL; typescript - classes | public fields in constructor</title>
      <dc:creator>Seyram Ofori</dc:creator>
      <pubDate>Thu, 15 Dec 2022 14:57:12 +0000</pubDate>
      <link>https://dev.to/seyofori/til-typescript-classes-public-fields-in-constructor-14gd</link>
      <guid>https://dev.to/seyofori/til-typescript-classes-public-fields-in-constructor-14gd</guid>
      <description>&lt;ul&gt;
&lt;li&gt;the use of &lt;code&gt;public&lt;/code&gt; on arguments on the constructor is a shorthand that allows us to automatically create properties with that name
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Student&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fullName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;in this case, the class has been given 3 public properties; fullName, firstName and lastName. firstName and lastName were created as public properties on the class by using the public keyword in the constructor params&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;classes in TS are just a shorthand for the same prototype-based OO that is frequently used in JS&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>TIL; JavaScript Jest - matchers</title>
      <dc:creator>Seyram Ofori</dc:creator>
      <pubDate>Thu, 15 Dec 2022 06:38:08 +0000</pubDate>
      <link>https://dev.to/seyofori/javascript-jest-til-matchers-1coh</link>
      <guid>https://dev.to/seyofori/javascript-jest-til-matchers-1coh</guid>
      <description>&lt;h2&gt;
  
  
  matchers
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;matchers allow you to test values by comparing the actual value to the expected value&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;expect&lt;/code&gt; returns an expectation object. you call matchers on this object to achieve the comparison of actual to expected.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBe&lt;/code&gt; matcher uses &lt;code&gt;[Object.is]&lt;/code&gt; to test exact equality.&lt;/li&gt;
&lt;li&gt;if you want to check the value of an object, use &lt;code&gt;toEqual&lt;/code&gt; or &lt;code&gt;toStrictEqual&lt;/code&gt; instead.

&lt;ul&gt;
&lt;li&gt;what does ‘check the value of an object’ mean?&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBe&lt;/code&gt; vs &lt;code&gt;toEqual&lt;/code&gt; vs &lt;code&gt;toStrictEqual&lt;/code&gt;. when to use which?

&lt;ul&gt;
&lt;li&gt;prefer &lt;code&gt;toStrictEqual&lt;/code&gt; over &lt;code&gt;toEqual&lt;/code&gt;, cos &lt;code&gt;toEqual&lt;/code&gt; simply ignores undefined values&lt;/li&gt;
&lt;li&gt;under which conditions would you want to ignore undefined values?&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;you can easily test the opposite of a matcher using &lt;code&gt;.not&lt;/code&gt;. eg: &lt;code&gt;expect(a+b).not.toStrictEqual(0)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  truthiness
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;matchers that allow you to be specific about the kind of truthy value you want&lt;/li&gt;
&lt;li&gt;there’s 5 of them&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeNull&lt;/code&gt; matches only &lt;code&gt;null&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeUndefined&lt;/code&gt; matches only &lt;code&gt;undefined&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeDefined&lt;/code&gt; is the opposite of &lt;code&gt;toBeUndefined&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeTruthy&lt;/code&gt; matches anything that an &lt;code&gt;if&lt;/code&gt; statement treats as true&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeFalsy&lt;/code&gt; matches anything that an &lt;code&gt;if&lt;/code&gt; statement treats as false&lt;/li&gt;
&lt;li&gt;you should use the matcher that most precisely corresponds to what you want your code to be doing&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  numbers
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;there’s 7 matchers that can be used for numbers&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toBeGreaterThan&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toBeGreatherThanOrEqual&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toBeLessThan&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toBeLessThanOrEqual&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toBe&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toEqual&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;toBeCloseTo&lt;/code&gt; ; to be used for floating point equality. cos we don’t want a test to depend on a tiny rounding error.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// this won't work cos of rounding error&lt;/span&gt;
&lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBeCloseTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// this works&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;toBe&lt;/code&gt; and &lt;code&gt;toEqual&lt;/code&gt; are equivalent for numbers&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  strings
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;you can check strings against regular expressions with &lt;code&gt;toMatch&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;expect('Christoph').toMatch(/stop/)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  arrays and iterables
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;you can check if an array or iterable contains a particular item using &lt;code&gt;toContain&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;expect(['diapers', 'paper towels']).toContain('paper towels');&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;JS iterables include the ff

&lt;ul&gt;
&lt;li&gt;string&lt;/li&gt;
&lt;li&gt;array&lt;/li&gt;
&lt;li&gt;TypedArray&lt;/li&gt;
&lt;li&gt;Map&lt;/li&gt;
&lt;li&gt;Set&lt;/li&gt;
&lt;li&gt;Segments (returned by Intl, Segmenter, prototype, segment())&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;an iterable is defined by the fact that its prototype object implements an &lt;code&gt;@@iterator&lt;/code&gt; method&lt;/p&gt;

&lt;h3&gt;
  
  
  exceptions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;to test whether a particular function throws an error when it’s called, use &lt;code&gt;toThrow&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;to check the error message, you can pass a regex to the &lt;code&gt;toThrow()&lt;/code&gt; matcher&lt;/li&gt;
&lt;li&gt;the function that throws an exception needs to be invoked within a wrapping function otherwise the &lt;code&gt;toThrow()&lt;/code&gt; assertion will fail.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
