Writing test specs for A-Frame

≡放荡痞女 提交于 2019-12-22 12:37:07

问题


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.
    });
  });
});


来源:https://stackoverflow.com/questions/41916358/writing-test-specs-for-a-frame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!