title: Faking a module in angular 2 test
body: <p>I have a function in angular 2 service which I would like to test.</p>
  
  <p><code>service.ts</code></p>
  
  <pre><code>upload(){
    let file = new Transfer();
    file.upload(myfile).then( // my callback );
  }
  </code></pre>
  
  <p>I would like to mock <code>Transfer</code> in my test using <code>jasmine</code>. I tried this in my</p>
  
  <p><code>sevice.spec.ts</code></p>
  
  <p><code>import { TransferMock as Transfer } from '../mocks/mocks'</code> to mock it. But it is not working. This is how my test is instantiated . </p>
  
  <pre><code>describe('authentication service' , () =&gt; {
    beforeEach(() =&gt; {
      auth = new Service(&lt;any&gt;new HttpMock(), &lt;any&gt;new StorageMock())
    });
    it('initialize authentication',() =&gt; {
      expect(auth).not.toEqual(null);
      auth.upload('file'); //it fails here
    });
  })
  </code></pre>
  
  <p><strong>edit</strong></p>
  
  <p><strong><code>Transfer</code> is not injected in the service.</strong> Only one function uses <code>Transfer</code> . So not injecting  can reduce the initial loading time of the app i guess(would be happy to know other opinions) . So I would like to know if there is anyway to mock if its constructed this way ? </p>
  
  <p><strong>edit</strong></p>
  
  <p>Although I had accepted Martin's answer as it is the best practice, it has one issue which can happen when you use <code>ionic-native</code> plugins.If the plugin doesnt have browser support it can fail. In this case it happened when I inject it, with error <code>FileTransfer is not defined</code> . So I am back again, looking for suggestions.</p>