@testing-library/react version: 10.2.13.5.04.0.183const dragNdropZone = component.getByTestId('drag-n-drop-zone');
const fileName = 'testFileName';
const fileItem = {
name: fileName,
size: 100,
type: 'file',
};
const fileEntry = {
name: fileName,
fullPath: `folder_one/folder_two/${fileName}`,
file: (resolve) => resolve(fileItem),
};
const itemOne = {
webkitGetAsEntry: () => fileEntry,
};
const dataTransfer = new DataTransfer();
Object.defineProperty(dataTransfer, 'items', {
value: [itemOne],
});
fireEvent.drop(dragNdropZone, { dataTransfer });
I am trying to test drag-and-drop functionality.
rtl overrides items in dataTransfer object assigning an empty array to it
If we check an event object passed to the onDrop handler of dragNdropZone we'll see that e.dataTransfer.files is an empty array even though we assigned an array with one item.
I am not able to mock items as a prop of dataTransfer object and test drag-and-drop functionality properly. NOTE: mocking worked correctly in rtl version 9.2.0
That solution looks good to me. But let's make sure to handle the case where DataTransfer is not supported by the environment as well.
Would you be interested in contributing this fix?
@kentcdodds I am sorry, it seems I need to submit the issue to dom-testing-library
I have moved the issue 馃槃
No worries @Snizhana :)
Thanks @marcosvega91!
I would be glad to work on it.
Does it sound good to all of you?
I'd still love to give @Snizhana a chance to work on it if they'd like. If we don't hear anything in the next day or so then go for it @delca85 馃憤 thanks!
@kentcdodds @delca85 my apology for the late reply. I have the PR, it is WIP since I still need to test it. if anyone has started work on the issue I'll close my PR. otherwise I will be grateful for any advice on testing and work verification.
:tada: This issue has been resolved in version 7.22.2 :tada:
The release is available on:
npm package (@latest dist-tag)Your semantic-release bot :package::rocket:
Most helpful comment
@kentcdodds @delca85 my apology for the late reply. I have the PR, it is WIP since I still need to test it. if anyone has started work on the issue I'll close my PR. otherwise I will be grateful for any advice on testing and work verification.