title: Mock a class used as property of a service
body: <p>I am actually developing an Ionic application. In this context, I implemented an <code>AlertService</code> class which has the two following properties:</p>
  
  <pre><code>messageAlert: Alert;
  errorAlert: Alert;
  </code></pre>
  
  <p>The <code>Alert</code> class is the one of the Ionic framework so I don't have any control on it. My idea was to mock the <code>Alert</code> class by a homemade mock like the following class:</p>
  
  <pre><code>class AlertMock {
      opts:       Object;
      presented:  boolean;
  
      constructor(opts) {
          this.opts       = opts;
          this.presented  = false;
      }
  
      present() {
          this.presented  = true;
      }
  
      dismiss() {
          this.presented  = false;
      }
  }
  </code></pre>
  
  <p>It will allow me to simply test the alert state by checking the value of the <code>presented</code> property.</p>
  
  <p>But how can I indicate to my <code>AlertService</code> that it two <code>Alert</code> properties are of type <code>AlertMock</code> instead? I don't know if it is even possible. But it seems to me quite basic to be able to mock class like that. Every topic I found talk about mocking service. With DI, it's very simple to replace a type by another, but is there any mechanism to do it with simple class like <code>Alert</code> of the Ionic framework?</p>