title: How to unit test private methods in Typescript
body: <p>When I tried to do unit testing for <strong>private methods in a Class</strong> getting error as <em>private methods are only accessible inside the class</em>. Here I added sample snippet for my class and mocha test. Kindly provide me solution to implement unit test for private methods.</p>
  
  <p><strong>Class Name: Notification.ts</strong> </p>
  
  <pre><code>class Notification {
   constructor() {}
   public validateTempalte() {
    return true;
   }
  
   private replacePlaceholder() {
    return true;
   }
  }
  </code></pre>
  
  <p><strong>Unit Test:</strong></p>
  
  <pre><code>import {Notification} from 'Notification';
  import * as chai from "chai";
  
  describe("Notification", function(){
  
    describe('#validateTempalte - Validate template', function() {
        it('it should return success', function() {
          const result = new Notification()
          chai.expect(result.validateTempalte()).to.be.equal(true);
        });
      });
    describe('#replacePlaceholder - Replace Placeholder', function() {
        it('it should return success', function() {
          const result = new Notification()
          // As expected getting error "Private is only accessible within class"
          chai.expect(result.replacePlaceholder()).to.be.equal(true);
        });
      });
  });
  </code></pre>
  
  <p>As a workaround, currently, I am changing access specifier of function <strong>replacePlaceholder</strong> to <strong>public</strong>. But I don't think its a valid approach. </p>