如何使用React Dnd

我使用react-dnd库在React中创建了一个拖放交互,我想测试,在拖放时,将调用某个函数。

但是,我在如何设置测试以使其通过方面受阻。

到目前为止,我的代码是:

it('should ',() => {
      const dropTarget = mountWithTheme(
        withRedux(store,<DnDCard fileId={folder._id} onClick={onClick} />),)

      const dragSource = mountWithTheme(
        withRedux(store,<DnDCard fileId={img._id} onClick={onClick} />)
      )

      var backend = getBackendFromInstance(<DnDCard fileId={folder._id} onClick={onClick} /> )
      var manager = backend.manager

      simulateDragDropSequence(dropTarget.instance(),dragSource.instance(),backend)
    })

在那个simulateDragDropSequence中,我收到一条错误消息:

  

Cannot read property 'getHandlerId' of null

这是因为function试图在其前两个参数上调用getHandlerId,但是显然实例没有提供该参数。

mountWithThemeReduxProvider一起添加到我们的组件中,因此效果很好。

这里是什么问题?

LE:读here时,getHandlerId是使用Legacy Decorator API设置组件时可用的实例方法,但我是使用Hooks(顶级API)完成的。我认为这可能是无法测试的原因。

sunyuantao123 回答:如何使用React Dnd

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3028505.html

大家都在问