title: Unit testing in Typescript with Dependency Injection using Inversify with mocha and chai
body: <p>I created typescript project using inversify and unit tests using mocha and chai. </p>
  
  <pre><code>@injectable()
  export class SomeClass{
  
  // Used in Constructor injection
  readonly object1:TypeObjectClass; 
  
  // Property Injection 
  (@inject(TYPE2)
  readonly someObject1:TypeSomeObjectClass1; 
  
  constructor(@inject(TYPE) object1: TypeObjectClass) {
  
  this.object1=object1
  
  }
  
  public someMethod(){
  
  this.object1.DoSomething();
  this.someObject1.DoAnything();
  
  }
  }
  </code></pre>
  
  <p>I wrote a unit test for the above class</p>
  
  <p>Unit Test</p>
  
  <pre><code>let chaiAsPromised = require('chai-as-promised');
  chai.use(chaiAsPromised);
  let expect = chai.expect;
  
  describe('Test Interaction Controller APIs', () =&gt; {
  
   let object1: IMock&lt;TypeObjectClass&gt;;
   let someObject: IMock&lt;TypeSomeObjectClass1&gt;;
  let someClass: SomeClass;
  
  beforeEach(()=&gt;{
  //Mock objects
   object1= Mock.ofType&lt;object1&gt;();
   someObject= Mock.ofType&lt;TypeSomeObjectClass1&gt;();
  // Constructor injected. 
  SomeClass=new SomeClass(object1.object)
  
  })
  
  }
  
  </code></pre>
  
  <p>How do I inject <code>someObject1</code> in my unit test since this is property injection? </p>