title: Angular 5: Unit testing getters and setters
body: <p>I am unable to test getter and setter functions in Angular 5 using Karma. Any ideas as to where I'm going wrong?</p>
  
  <p>The value is set and then the test waits a short duration for the setter function to resolve before calling the getter function. Here is the code:</p>
  
  <p><strong>service.ts</strong></p>
  
  <pre><code>set header(h: string) {
      this.zone.run(() =&gt; {
          this._header = h;
      });
  }
  
  get header(): string {
      return this._header;
  }
  </code></pre>
  
  <p><strong>test.ts</strong></p>
  
  <pre><code>before(() =&gt; {
      service = new Service()
  });
  
  it('updates header', (done) =&gt; {
      const header = 'test header';
      service.header = header;
  
      // Give header time to update
      return Promise.delay(200)
      .then(() =&gt; {
           expect(service.header).to.equal(header);
      })
  });
  </code></pre>
  
  <p>I would expect the assertion to resolve successfully however I get an error </p>
  
  <blockquote>
    <p>AssertionError: expected undefined to equal 'test header'</p>
  </blockquote>