title: jest (Angular): change value of spyon().mockReturnValue
body: <p>In two different tests I want to mock two different values of a function in a given service. I use:</p>
  
  <pre><code>    service = TestBed.get(someService);
      spyObj = jest.spyOn(service, 'someFunction').mockReturnValue(of('foo'));
  </code></pre>
  
  <p>and the first test runs well. Then if I write either</p>
  
  <pre><code>    spyObj.mockReturnValue(of('second foo'));
  </code></pre>
  
  <p>or</p>
  
  <pre><code>    spyObj = jest.spyOn(someService, 'someMethod').mockReturnValue(of('foo'));
  </code></pre>
  
  <p>in the second test, the value I get is still 'foo'. I tried also <code>mockClear</code>, <code>mockReset</code> and <code>mockRestore</code> and none of them seems to do anything at all. I always get 'foo'.</p>
  
  <p><strong>What should I do to get a different value in my second test?</strong></p>
  
  <p>I have the following versions of <code>jest</code>:</p>
  
  <pre><code>    "jest": "^24.1.0",
      "jest-junit": "^6.3.0",
      "jest-preset-angular": "^6.0.2",
  </code></pre>
  
  <p>I can't update <code>jest-preset-angular</code> because I have <a href="https://stackoverflow.com/questions/55810980/using-jest-i-get-cannot-find-type-definition-file-for-jasmine">this non-solved problem</a>. :-(</p>
  
  <p>Here the code a bit more expanded:</p>
  
  <pre><code>describe('whatever', () =&gt; {
    let component: SomeComponent;
    let fixture: ComponentFixture&lt;SomeComponent&gt;;
    let someService: SomeService;
    let spyObj: jest.Mock&lt;Observable&lt;any&gt;, [string | string[], object?]&gt;;
  
    beforeEach(async(() =&gt; {
      TestBed.configureTestingModule({
        imports: [
          SomeModule.forRoot()
        ],
        declarations: [ SomeComponent ],
        providers: [ SomeService ]
      })
      .compileComponents();
    }));
  
    beforeEach(() =&gt; {
      someService = TestBed.get(SomeService);
      spyObj = jest.spyOn(someService, 'someMethod').mockReturnValue(of('foo'));
      fixture = TestBed.createComponent(SomeComponent);
      component = fixture.componentInstance;
      fixture.detectChanges();
    });
  
    afterEach(() =&gt; {
      fixture.destroy();
    });
  
    it('should create', () =&gt; {
      expect(component).toBeTruthy();
    });
  
    it('should check someFunction when someService returns "foo"', () =&gt; {
      component.someFunction(); // This function uses the value of someService
      // Debugging inside someFunction I get "foo"
      expect(component.something).toEqual('foo');
    });
  
    it('should check someFunction when someService returns "second foo"', () =&gt; {
      spyObj.mockReturnValue(of('second foo'));
  
  // this does not work either:
  //    spyObj = jest.spyOn(someService, 'someMethod').mockReturnValue(of('second foo'));
  
      component.someFunction(); // This function uses the value of someService
      // Debugging inside someFunction I still get "foo"
      expect(component.something).toEqual('second foo');
    });
  });
  </code></pre>