Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I simulate drag and drop in enzyme testcase?

I am trying to create a test for simulating a dragging of an image into a div. I am clueless on how to achieve this. Any help is much appreciated.

it('test drag and drop', () => {
    const app = mount(<App />);
    const loco = app.find('.app img');
    const dropTarget = app.find('.drop-target');
    let mockEvent = { dataTransfer: { type: 'test' } };
    loco.simulate('drag', mockEvent);
    //loco.simulate('dragover', dropTarget, mockEvent);
    //loco.simulate('drop', dropTarget, mockEvent);
});

I am trying to simulate the drop event, not sure how to do as 2 elements are involved in it.

Thanks, Saud

like image 299
Saud Avatar asked Nov 13 '17 20:11

Saud


1 Answers

What DnD Component do you use? React-Dnd? Maybe this issue on Github can help you. Or maybe this article about testing Drag&Drop via Jest.

like image 163
bitwikinger Avatar answered Oct 16 '22 14:10

bitwikinger