You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
following code provided by chatgpt seems legit, but fired events won't change state of isDragActive
import{render,fireEvent}from'@testing-library/react';import{useDropzone}from'react-dropzone';functionDropzoneComponent(){const{ getRootProps, getInputProps, isDragActive }=useDropzone({});return(<divdata-testid="dropzone"{...getRootProps()}><inputdata-testid="input"{...getInputProps()}/>{isDragActive&&<divdata-testid="drag-active">Drop file here</div>}</div>);}describe('Dropzone component',()=>{it('should set isDragActive state to true when dragging over the dropzone',()=>{const{ getByTestId }=render(<DropzoneComponent/>);constdropzone=getByTestId('dropzone');constinput=getByTestId('input');constfile=newFile(['Hello, world!'],'hello.txt',{type: 'text/plain'});constdataTransfer={dataTransfer: {files: [file],types: ['Files'],},};fireEvent.dragEnter(dropzone);fireEvent.dragOver(dropzone,dataTransfer);expect(getByTestId('drag-active')).toBeInTheDocument();fireEvent.dragLeave(dropzone);fireEvent.dragEnter(input);fireEvent.dragOver(input,dataTransfer);expect(getByTestId('drag-active')).toBeInTheDocument();});});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
following code provided by chatgpt seems legit, but fired events won't change state of
isDragActive
Beta Was this translation helpful? Give feedback.
All reactions