title: Import json file to mock data for my tests
body: <p>I try to mock data in my jasmine tests.</p>
  
  <p>In a component spec I use:</p>
  
  <pre><code>describe('MyComponent', () =&gt; {
    const user: User = require('../../mocks/user.json');
  </code></pre>
  
  <p>I a service stub that I put inside <em>/src/mocks/services/service.stub.ts</em></p>
  
  <pre><code>import { Observable, of } from 'rxjs';
  
  export const MyServiceStub =  {
    users: require('../../mocks/users.json'),
  
    getUsers(): Observable&lt;any&gt; {
      return of(this.users);
    }
  };
  </code></pre>
  
  <p>With this <em>npm run test</em> works but the app doesn't compile because of</p>
  
  <blockquote>
    <p>ERROR in src/app/mocks/services/UserServiceStub.ts(4,15): error
    TS2304: Cannot find name 'require'.</p>
  </blockquote>
  
  <p>I've tried modifying <em>tsconfig.json</em> with</p>
  
  <pre><code>"compilerOptions": {
      "resolveJsonModule": true,
      "esModuleInterop": true  
    }
  </code></pre>
  
  <p>And import mocks json with:</p>
  
  <pre><code>import * as users from '../../mocks/users.json';
  </code></pre>
  
  <p>This destroyed all my imports like momentJS (import * as moment from 'moment')</p>
  
  <p>I read I could just add</p>
  
  <pre><code>"allowSyntheticDefaultImports": true
  </code></pre>
  
  <p>But this didn't help...</p>
  
  <p>What's the right way to import a json file in my tests?</p>
  
  <p>EDIT: I forgot to say that <em>require</em> works in my spec files, it just fails when I use it in <em>/src/mocks/services/MyService.stub.ts</em></p>
  
  <p>I modified the stubbed service to be a class and changed the provider to use <em>useClass</em> instead of <em>useValue</em> but this didn't help.</p>