<?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: SARA-AHMED94</title>
    <description>The latest articles on DEV Community by SARA-AHMED94 (@saraahmed94).</description>
    <link>https://dev.to/saraahmed94</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%2F577874%2Ff7f691b4-97d9-4278-98a8-232cefa9c92e.jpeg</url>
      <title>DEV Community: SARA-AHMED94</title>
      <link>https://dev.to/saraahmed94</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saraahmed94"/>
    <language>en</language>
    <item>
      <title>Test Asynchronous Calls With the Jest</title>
      <dc:creator>SARA-AHMED94</dc:creator>
      <pubDate>Sat, 26 Jun 2021 00:54:22 +0000</pubDate>
      <link>https://dev.to/saraahmed94/test-asynchronous-calls-with-the-jest-4phi</link>
      <guid>https://dev.to/saraahmed94/test-asynchronous-calls-with-the-jest-4phi</guid>
      <description>&lt;p&gt;It's common in JavaScript for code to run asynchronously. When you have code that runs asynchronously, Jest needs to know when the code it is testing has completed, before it can move on to another test. Jest has several ways to handle this.&lt;/p&gt;

&lt;p&gt;Asynchronous calls don’t block or wait for calls to return. After the call is made, program execution continues. When the call returns, a callback function is executed. It’s hard to test asynchronous calls due to the asynchronous nature.&lt;/p&gt;

&lt;h2&gt;
  
  
  Callback-based asynchronous calls
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Problem of Asynchronous Calls
&lt;/h3&gt;

&lt;p&gt;The following is a unit test case for an asynchronous call&lt;/p&gt;

&lt;pre&gt;
describe('test asynchronous call', () =&amp;gt; {
  it('this should not pass', () =&amp;gt; {
    setTimeout(() =&amp;gt; {
      expect(1).toBe(2);
    });
  });
});

&lt;/pre&gt;

&lt;p&gt;Apparently, 1 isn’t 2, but the test passes.&lt;br&gt;
setTimeout is called and returns. The test finishes before  inside the  setTimeout is  executed. No error is found before the test exits — therefore, the test case passes.&lt;/p&gt;

&lt;h3&gt;
  
  
  The fix: Use the ‘done’ callback
&lt;/h3&gt;

&lt;p&gt;We can fix this issue by waiting for setTimeout to finish.&lt;/p&gt;

&lt;pre&gt;
describe('test asynchronous call', () =&amp;gt; {
  it('this should not pass', done =&amp;gt; {
    setTimeout(() =&amp;gt; {
      expect(1).toBe(2);
      done();
    });
  });
});
&lt;/pre&gt;

&lt;p&gt;We pass in Jest’s done callback to the test case and wait for setTimeout to finish. And then we invoke done() to tell Jest it can exit now. With the help of the done callback, this test case fails as expected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Promise-Based Asynchronous Calls
&lt;/h2&gt;

&lt;p&gt;If your code uses promises, there is simpler way to handle asynchronous tests. Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail.&lt;/p&gt;

&lt;p&gt;For example, let's say that fetchData returns a promise that is supposed to resolve to the string 'peanut butter'. We could test it with:&lt;/p&gt;

&lt;pre&gt;
test('the data is peanut butter', () =&amp;gt; {
  return fetchData().then((data) =&amp;gt; {
    expect(data).toBe('peanut butter');
  });
})
&lt;/pre&gt;

&lt;p&gt;Be sure to return the promise - if you omit this return statement, your test will complete before fetchData completes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We have explored the main asynchronous patterns on JavaScript and the ways to test them with Jest. &lt;/p&gt;

</description>
      <category>testing</category>
    </item>
    <item>
      <title>BEM methodology</title>
      <dc:creator>SARA-AHMED94</dc:creator>
      <pubDate>Thu, 11 Feb 2021 23:17:42 +0000</pubDate>
      <link>https://dev.to/saraahmed94/bem-methodology-1o33</link>
      <guid>https://dev.to/saraahmed94/bem-methodology-1o33</guid>
      <description>&lt;p&gt;CSS is a language that is easy to learn but very hard to maintain. As the project grows larger, without proper structure, maintaining CSS is unbearable.BEM is an approach for improving CSS structure.&lt;/p&gt;

&lt;p&gt;BEM stands for Block Element, Modifiers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
A BEM class name includes three parts.&lt;/p&gt;

&lt;p&gt;1- Block: The outermost parent element of the component is defined &lt;br&gt;
   as the block.&lt;br&gt;
2- Element: Inside of the component may be one or more children &lt;br&gt;
   called elements.&lt;br&gt;
3- Modifier: Either a block or element may have a variation &lt;br&gt;
   signified by a modifier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Block&lt;/strong&gt;&lt;br&gt;
A Block is a component part of a website that can exist in it’s own right. We’re using a product card as our example Block.&lt;/p&gt;

&lt;p&gt;Naming : Block names may consist of Latin letters, digits, and dashes. To form a CSS class, add a short prefix for namespacing&lt;/p&gt;

&lt;p&gt;Example : .block&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3AifIqp3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://keepinguptodate.com/pages/2020/05/02-bem-block-example.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3AifIqp3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://keepinguptodate.com/pages/2020/05/02-bem-block-example.svg" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Element&lt;/strong&gt;&lt;br&gt;
An Element is a child aspect of a Block that only exists within that Block. In our product card example, image, title, price and like-button are all examples of Elements within the product card Block.&lt;/p&gt;

&lt;p&gt;Naming : Element names may consist of Latin letters, digits, dashes and underscores. CSS class is formed as block name plus two underscores plus element name&lt;/p&gt;

&lt;p&gt;Example : .block__elem&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2J8NXkV3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://keepinguptodate.com/pages/2020/05/03-bem-element-examples.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2J8NXkV3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://keepinguptodate.com/pages/2020/05/03-bem-element-examples.svg" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Modifier&lt;/strong&gt;&lt;br&gt;
A Modifier can be applied to either a Block or an Element and is used to adjust the default look or behaviour of the Block or Element. With our product card example, the Modifier liked exists and can be applied to both the product card Block and the like-button Element when a product has been liked&lt;/p&gt;

&lt;p&gt;Naming : Modifier names may consist of Latin letters, digits, dashes and underscores. CSS class is formed as block’s or element’s name plus two dashes&lt;/p&gt;

&lt;p&gt;Example : .block--mod&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ip5cl-rn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://keepinguptodate.com/pages/2020/05/04-bem-modifier-examples.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ip5cl-rn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://keepinguptodate.com/pages/2020/05/04-bem-modifier-examples.svg" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Overall, I would highly recommend using it on your next project. It may be different than what you’re used to,but I’m convinced you’ll quickly see the benefits it provides on projects both large and small. It will save you So much debugging time in the future. Hopefully, you find this article useful.&lt;/p&gt;

</description>
      <category>css</category>
    </item>
  </channel>
</rss>
