Reactjs 用于反应单元测试的Jest和酶模拟onDrag事件

Reactjs 用于反应单元测试的Jest和酶模拟onDrag事件,reactjs,unit-testing,drag-and-drop,jestjs,enzyme,Reactjs,Unit Testing,Drag And Drop,Jestjs,Enzyme,在我的单元测试中模拟拖动事件时出现问题。Spy从不与dragStart和dragExit相反调用。工作模式是基于鼠标事件和拖动的,当然不是-许多尝试以奇怪的方式模拟它,如: wrapper.find('Draggable').simulate('mouseDown').simulate('mouseMove',{PageY:100}).simulate('mouseUp') …失败,因此这是我的实际描述块: it('should call dragStart()', () => {

在我的单元测试中模拟拖动事件时出现问题。Spy从不与dragStartdragExit相反调用。工作模式是基于鼠标事件和拖动的,当然不是-许多尝试以奇怪的方式模拟它,如:
wrapper.find('Draggable').simulate('mouseDown').simulate('mouseMove',{PageY:100}).simulate('mouseUp')

…失败,因此这是我的实际描述块:

it('should call dragStart()', () => {
    wrapper.find('Draggable').simulate('mouseDown');
    expect(wrapper.instance().props.dragStart).toHaveBeenCalled(); // PASS
});
it('should call dragExit()', () => {
    wrapper.find('Draggable').simulate('mouseDown').simulate('mouseUp');
    expect(wrapper.instance().props.dragExit).toHaveBeenCalled(); // PASS
});
it('should call dragMove()', () => {
    wrapper.find('Draggable').simulate('drag');
    expect(wrapper.instance().props.dragMove).toHaveBeenCalled(); // FAIL
});
我如何模拟这种拖动?我选择了react draggabledependency。我使用enzymemount和jest.fn()间谍道具来渲染我的包装。请寻求帮助,如果您需要更多信息,只需说!:)

PS:我知道,但我想用产生同样的效果,但我的努力以一点也不叫spy而告终:

wrapper.find('Draggable').simulate('mouseDown', {clientX: 0, clientY: 0}).simulate('mouseMove', {clientX: 0, clientY: 100}).simulate('mouseUp');

出于好奇,为什么要测试可拖动组件?看起来依赖性已经有了类似的测试,但是没有酶:@LukeHutton我在我的帖子中添加了PS作为对你的回应。