title: Angular2, TypeScript, PhantomJS - Can't find variable: Audio
body: <p>PhantomJS doesn't support HTML5 Audio tags, which is making it difficult to test my Angular2 app. I've looked around for a solution, but unfortunately I haven't been able to figure out a way to mock the Audio object or somehow get around this. I have an Angular2 service that looks like this:</p>
  
  <pre><code>import {Injectable} from 'angular2/core';
  
  @Injectable()
  export class MyService {
    var snd;
  
    constructor() {
      this.snd = new Audio('Assets/sound.wav');
    }
  
    simpleFunction() {
      return true;
    }
  }
  </code></pre>
  
  <p>My test looks like this:</p>
  
  <pre><code>import {describe, expect, it} from 'angular2/testing';
  import {Component} from 'angular2/core';
  import {MyService} from 'my.service';
  
  export function main() {
    describe('My service', () =&gt; {
      var myService: MyService = new MyService();
  
      it('should work', () =&gt; {
        expect(myService.simpleFunction).toEqual(true);
      });
  
    });
  }
  </code></pre>
  
  <p>This is of course a simplified version, but it demonstrates the issue I'm having. When I run my test, I receive this error:</p>
  
  <pre><code>ReferenceError: Can't find variable: Audio
  </code></pre>
  
  <p>I haven't been able to figure out how to avert this from happening in my tests. I have tried this in my service:</p>
  
  <pre><code>if (Audio !== undefined) 
  </code></pre>
  
  <p>To check before the 'snd' variable is assigned, but I still got the same result.</p>