title: Testing a Angular 9 service using Jest and Testbed
body: <p>In my Angular 9 project I added <code>jest</code> and removed <code>Jasmine</code> and <code>Karma</code>.</p>
  
  <p>I'm testing a service called <code>CorrectionService</code> that has a dependency of a service called <code>RemoteService</code>.</p>
  
  <p>I want to spy on the <code>RemoteService</code> to see if a method is called. I've successfully done it by mocking manually with jest the <code>RemoteService</code>.</p>
  
  <p>Now I want to use <code>TestBed</code>. My previous Jasmine test is this:</p>
  
  <pre class="lang-js prettyprint-override"><code>import { TestBed } from '@angular/core/testing';
  import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
  import { HttpClient } from '@angular/common/http';
  import { CorrectionService } from './correction.service';
  import { Answer, Question } from './setting';
  import { IChoosed } from './question/question.component';
  import { RemoteService } from './remote.service';
  
  
  describe('CorrectionService', () =&gt; {
    let service: CorrectionService;
    let remoteServiceSpy: jasmine.SpyObj&lt;RemoteService&gt;
  
    beforeEach(() =&gt; {
      const spy = jasmine.createSpyObj('RemoteService', ['saveToRemoteAdditionalData']);
      TestBed.configureTestingModule({
        imports: [HttpClientTestingModule],
        providers: [
          CorrectionService,
          {provide: RemoteService, useValue: spy}
        ]
      });
      service = TestBed.inject(CorrectionService);
      remoteServiceSpy = TestBed.inject(RemoteService) as jasmine.SpyObj&lt;RemoteService&gt;;
    });
  </code></pre>
  
  <p>I've tried to use <code>jest</code> mock this way:</p>
  
  <pre class="lang-js prettyprint-override"><code>import { TestBed } from '@angular/core/testing';
  import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
  import { HttpClient, HttpHandler } from '@angular/common/http';
  import { CorrectionService } from './correction.service';
  import { Answer, Question } from './setting';
  import { IChoosed } from './question/question.component';
  import { RemoteService } from './remote.service';
  
  
  describe('CorrectionService', () =&gt; {
    let service: CorrectionService;
    this.remoteServiceStub = {} as RemoteService;
  
    beforeEach(() =&gt; {
      this.remoteServiceStub = {saveToRemoteAdditionalData: jest.fn()};
  
      TestBed.configureTestingModule({
        imports: [HttpClientTestingModule],
        providers:[
          CorrectionService,
          {provide:RemoteService, useValue: this.remoteServiceStub}
        ]
      });
      this.service = TestBed.inject(CorrectionService);
      TestBed.inject(RemoteService);
    });
  
  </code></pre>
  
  <p>But the tests arent working and I got:</p>
  
  <pre><code> Can't resolve all parameters for CorrectionService: (?).
  </code></pre>
  
  <p>I guess <code>RemoteService</code> is not injected. What I'm doing wrong?</p>