jeudi 30 juillet 2015

How do I test something which requests permissions on standard browsers?

I have a basic camera class in es6. One method requests permissions. I'll just simplify it.

class Camera {
  // omit unimportant details
  getStream() {
    return new Promise((resolve, reject) => {
      navigator.webkitGetUserMedia({ video: true }, (stream) => {
        this.video.attr('src', window.URL.createObjectURL(stream));
      });
    });
  }
}
window.camera = Camera;

However, there seems to be a problem. I have a small unit test with meteor's package test framework.

Tinytest.addAsync('Should set the video url', function (test, next) {
  let camera = new window.Camera();
  camera.getStream().then((stream) => {
    test.isNotUndefined(stream);
    test.equals(camera.video.attr('src', window.URL.createObjectURL(stream)));
    next();
  }).catch((err) => {
    test.fail(err);
    next();
  })
});

However, this tests halts because it has to request permissions from the browser to use the user media.

How can you test a package which requests data?

Aucun commentaire:

Enregistrer un commentaire