<?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: eggsys</title>
    <description>The latest articles on DEV Community by eggsys (@eggsys).</description>
    <link>https://dev.to/eggsys</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%2F641801%2Fbc323301-007a-439e-b2dc-3cd70a6a9278.jpeg</url>
      <title>DEV Community: eggsys</title>
      <link>https://dev.to/eggsys</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eggsys"/>
    <language>en</language>
    <item>
      <title>Answer: Testing private method using spyOn and Jest</title>
      <dc:creator>eggsys</dc:creator>
      <pubDate>Thu, 11 Aug 2022 13:16:35 +0000</pubDate>
      <link>https://dev.to/eggsys/answer-testing-private-method-using-spyon-and-jest-3gff</link>
      <guid>https://dev.to/eggsys/answer-testing-private-method-using-spyon-and-jest-3gff</guid>
      <description>&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;div class="ltag__stackexchange--header"&gt;
          &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Gn-iPj_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
          &lt;a href="https://stackoverflow.com/questions/62171602/testing-private-method-using-spyon-and-jest/67418048#67418048" rel="noopener noreferrer"&gt;
            &lt;span class="title-flare"&gt;answer&lt;/span&gt; re: Testing private method using spyOn and Jest
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;May  6 '21&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/62171602/testing-private-method-using-spyon-and-jest/67418048#67418048" rel="noopener noreferrer"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y9mJpuJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          4
        &lt;/div&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wif5Zq3z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;you can try &lt;code&gt;jest.spyOn&lt;/code&gt; for get implementation of private method&lt;/p&gt;
&lt;p&gt;Class&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;export default class Calculator {
  private Sum(a: number, b: number): number {
    let c = a + b;
    return c;
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Test&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;const handleErrorSpy = jest.spyOn(Calculator.prototype, 'Sum');
const getSumImplementation = handleErrorSpy.getMockImplementation();

expect(getSumImplementation(1, 2)).toEqual(3);

&lt;/code&gt;&lt;/pre&gt;

    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    &lt;a href="https://stackoverflow.com/questions/62171602/testing-private-method-using-spyon-and-jest/67418048#67418048" class="ltag__stackexchange--btn" rel="noopener noreferrer"&gt;Open Full Answer&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
    </item>
  </channel>
</rss>
