mardi 22 septembre 2015

How to Release AudioContext in Jasmine Tests

I've got an Angular service that sets up an audioContext. Jasmine is creating a new service for each test, so after 6 tests all tests fail with the error:

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

Is there a way for me to clear the AudioContext between tests? I've tried AudioPlayer.context.close() in an afterEach block, but doesn't seem to be working.

service looks kinda like this:

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

    self.context = new AudioContext();

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

and tests looks kinda like this:

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

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

  it('does cool stuff', function () {
        // unit tests...
  });
});

Thanks for the help!

Aucun commentaire:

Enregistrer un commentaire