首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >测试自定义A帧事件时使用React和aframe-react

测试自定义A帧事件时使用React和aframe-react
EN

Stack Overflow用户
提问于 2017-04-17 13:38:01
回答 1查看 594关注 0票数 1

MathworldVR项目(https://github.com/michaltakac/mathworldvr)中,我使用的是aframe-super-hands-component,当用户点击/离开实体时,它会触发'hover-start''hover-end'事件。一切都如期而至。

但是,如何从内部测试中调用这些事件呢?当A帧实体使用TestUtilsshallowreact-test-rendererrenderer或Jest呈现时,我无法从react-dom/test-utils中模拟这些实体,因为它只能模拟传统反应事件

CalcButton组件代码:

代码语言:javascript
复制
import 'aframe'
import 'super-hands'
import React from 'react'
import { Entity } from 'aframe-react'

export default class CalcButton extends React.Component {
  constructor(props) {
    super(props)

    this.state = {
      depth: 0.02,
      opacity: 1,
    }

    this.startIntersection = this.startIntersection.bind(this)
    this.endIntersection = this.endIntersection.bind(this)
  }

  startIntersection() {
    this.setState({ depth: 0, opacity: 0.2 })
  }

  endIntersection() {
    this.setState({ depth: 0.02, opacity: 1 })
  }

  render() {
    const { depth, opacity } = this.state
    return (
      <Entity
        className="interactive"
        geometry={{ primitive: 'box', height: 1, width: 1, depth }}
        material={{ shader: 'flat', side: 'double', color: 'green', opacity }}
        scale={{ x: 0.5, y: 0.5, z: 0.5 }}
        position={{ x: 0.5, y: 0.5, z: 0.5 }}
        hoverable
        events={{
          'hover-start': this.startIntersection,
          'hover-end': this.endIntersection,
        }}
      >
        <Entity text="Test button" />
      </Entity>
    )
  }
}

拟议的CalcButton测试:

代码语言:javascript
复制
import React from 'react'
import { shallow } from 'enzyme'
import CalcButton from '.'

jest.mock('react-dom')

describe('CalcButton', () => {
  it('simulates hover-start event', () => {
    const wrapper = shallow(<CalcButton />)
    // TODO: Somehow figure out how to simulate event and
    // check if <a-entity> has a geometry.opacity equal to 0.2
  })
})
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-17 18:15:26

对于实际的浏览器测试,我将使用。查看aframe的测试线束:https://github.com/aframevr/aframe-react/tree/master/tests/browser。有反应测试,反应呈现和反应级别的东西,和浏览器测试,测试完全集成,包括事件。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43452619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档