title: How to mock/spy an imported function in Angular unit testing
body: <p>Let's say i have an angular 6 component with a method <code>test</code> which returns some value:</p>
  
  <pre><code>import { doSomething } from './helper';
  
  @Component({
      ...
  })
  export class AppComponent {
      test() {
          const data = doSomething(1);
          return data.something ? 1: 2;
      }
  }
  </code></pre>
  
  <p><code>doSomething</code> is just a simple helper function:</p>
  
  <pre><code>export function doSomething() {
      return { something: 1 };
  }
  </code></pre>
  
  <p>Is it possible to mock or spy this function in a unit test (so i can control its returnValue)? Or do i have to change my approach in the component?</p>
  
  <p>Please note: <code>doSomething()</code> can be a lodash function, a const, a class etc. I just tried to keep the example as simple as possible.</p>
  
  <hr>
  
  <p>Things i've tried:</p>
  
  <ul>
  <li><p><code>SpyOn</code> doesn't work because function is not attached to anything</p></li>
  <li><p>Importing an mock-function into the <code>imports</code> array of <code>TestBed.configureTestingModule</code> gives <code>Unexpected value 'doSomething' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation.</code></p></li>
  <li><p>Creating a service for it works but it feels silly to have to create services for each imported function</p></li>
  </ul>