Writing test specs for A-Frame

2019-05-20 21:57发布

问题:

I'm totally new to VR and am working on a Vr space shooter in AFrame for a class project and was wondering if there is any documentation/standards for TDD in AFrame. Could anyone point me in the right direction?

回答1:

Build your application almost entirely in A-Frame components: https://aframe.io/docs/0.4.0/guides/writing-a-component.html

Then test the components. Just about every component in the A-Frame codebase has unit tests: https://github.com/aframevr/aframe/tree/master/tests/components

The component template in angle also has a unit test setup. https://github.com/aframevr/angle/tree/master/templates/component (npm install -g angle && angle initcomponent for a standalone component).

The tests use Karma to spin up a real browser and execute code. It appends entities to the DOM, and attaches components with different property values, and asserts values. A basic example:

suite('foo component', function () {
  var component;
  var el;

  setup(function (done) {
    el = entityFactory();
    el.addEventListener('componentinitialized', function (evt) {
      if (evt.detail.name !== 'foo') { return; }
      component = el.components.foo;
      done();
    });
    el.setAttribute('foo', {});
  });

  suite('update', function () {
    test('bar', function () {
      el.setAttribute('foo', 'bar', 10);
      assert.equal(component.baz, 10);  // Assert something.
    });
  });
});


标签: aframe