PhantomJS不支持HTML5音頻標籤,這很難測試我的Angular2應用程序。我已經四處尋找解決方案,但不幸的是我一直無法找出一種方法來模擬音頻對象或以某種方式解決這個問題。我有一個Angular2服務,看起來像這樣:Angular2,TypeScript,PhantomJS - 找不到變量:音頻
import {Injectable} from 'angular2/core';
@Injectable()
export class MyService {
var snd;
constructor() {
this.snd = new Audio('Assets/sound.wav');
}
simpleFunction() {
return true;
}
}
我的測試是這樣的:
import {describe, expect, it} from 'angular2/testing';
import {Component} from 'angular2/core';
import {MyService} from 'my.service';
export function main() {
describe('My service',() => {
var myService: MyService = new MyService();
it('should work',() => {
expect(myService.simpleFunction).toEqual(true);
});
});
}
當然這是一個簡化版本,但它證明了我有這個問題。當我運行我的測試,我收到此錯誤:
ReferenceError: Can't find variable: Audio
我一直無法弄清楚如何從我的測試中發生避免這種。我在我的服務中試過這個:
if (Audio !== undefined)
在'snd'變量被分配之前檢查,但我仍然得到相同的結果。
我想你錯過了在課堂注入音頻? –
@PankajParkar不,這是全球性的'window.Audio'構造函數。 – dfsq