Skip to content

Lupa API Reference / @pawel-up/lupa/testing / createFileDragEvent

Function: createFileDragEvent()

createFileDragEvent(type, files, options?): DragEvent

Defined in: src/testing/helpers.ts:165

Creates a browser-side custom file DragEvent that can be dispatched to elements.

Parameters

type

DragEventType

Standard drag event name (e.g. 'dragover', 'drop').

files

File[]

Array of standard DOM Files to attach to the dataTransfer property.

options?

DragEventInit

Custom event init options to merge.

Returns

DragEvent

A standard DOM DragEvent populated with the files.

Use

when

  • Testing drag-and-drop file upload zones inside tests.

Dont

use when

  • Simulating user mouse drag-and-drop of elements on the page (use query().dragTo() instead).

Example

typescript
import { createFileDragEvent } from '@pawel-up/lupa/testing'

const file = new File(['hello'], 'hello.txt', { type: 'text/plain' })
const event = createFileDragEvent('drop', [file])
dropzone.dispatchEvent(event)