title: Jasmine Spy On a Typescript Class Get() or Set() function
body: <p>I am using Jasmine 2.9 and I have not have problems spying on a function whether it was public or private but I am having difficulty trying to spy on a <code>get</code> or <code>set</code> function on the class level. </p>
  
  <pre><code>private class RandomService {
    public dogsHealth = 0;
  
    private get personsFullName(): string {
      return firstName + lastname;
    }
  
    private set personsLocation(address: string, city: string, country: string): string {
      return address + city + country;
    }
  
    public get dogsFullName(): string {
      return dogFirstName + dogLastName;
    }
  
    public get isDogAlive(): boolean {
      return dogsHealth &lt;= 0 ? true : false;
    }
  }
  </code></pre>
  
  <p>Solutions I tried:</p>
  
  <pre><code>spyOnProperty(RandomService, 'dogsFullName', 'get').and.returnValue(true);
  spyOnProperty(RandomService, 'dogsFullName').and.returnValue(true);
  spyOn(RandomService, 'dogsFullName').and.returnValue(true);
  spyOnProperty(RandomService.dogsFullName, 'dogsFullName', 'get').and.returnValue(true);
  </code></pre>
  
  <p>Currently I have not found a solution to this online but will continue looking. I know the get or set functions creates a variable so I thought perhaps solution 4 would have worked but still no.</p>
  
  <h2>Update</h2>
  
  <p>(The code above is also updated).</p>
  
  <p>Trying the update to return a string and using the following jasmine give me an error:</p>
  
  <pre><code>spyOnProperty(RandomService, 'dogsFullName', 'get').and.returnValue('Frank');
  </code></pre>
  
  <p><code>Expected a spy, but got 'Frank'</code></p>
  
  <p>As well as for the function <code>isDogAlive</code> I get the following:</p>
  
  <pre><code>&lt;toHaveBeenCalled&gt; : Expected a spy, but got true.
  </code></pre>
  
  <p>I understand it is giving me the correct value but if I <code>spyOn</code> it then should it not be a spy?</p>