0

audioContext を設定する Angular サービスがあります。Jasmine はテストごとに新しいサービスを作成しているため、6 回のテストの後、すべてのテストがエラーで失敗します。

Error: Failed to construct 'AudioContext': The number of hardware contexts provided (6) is greater than or equal to the maximum bound (6).

テスト間で AudioContext をクリアする方法はありますか? afterEach ブロックで試してみAudioPlayer.context.close()ましたが、機能していないようです。

サービスは次のようになります。

angular.module('myApp')
  .service('AudioPlayer', function () {

    var self = this;

    self.context = new AudioContext();

    this.doSomething = function () {
       // doing super cool testable stuff here
    }
  })

テストは次のようになります。

describe('AudioPlayer', function () {
  var AudioPlayer;

  beforeEach(function () {
    inject(function ($injector) {
      AudioPlayer = $injector.get('AudioPlayer');
    });
  });

  afterEach(function () {
    AudioPlayer.context.close();
  });

  it('does cool stuff', function () {
    AudioPlayer.doSomething();    
    // unit test
  });

  it('does other cool stuff', function () {
    AudioPlayer.doSomething();    
    // unit test
  });

});

助けてくれてありがとう!

問題を示す jsFiddle は次のとおりです: http://jsfiddle.net/briankeane/cp929can/1/

4

2 に答える 2