import { fireEvent } from '@testing-library/dom' ; import { Config , Instance } from '../setup' ; import { copySelection , writeDataTransferToClipboard } from '../utils' ; export async function copy ( this ) { const doc = this [ Config ] . document ; const target = doc . activeElement ?? doc . body ; const clipboardData = copySelection ( target ) ; if ( clipboardData . items . length === 0 ) { return ; } fireEvent . copy ( target , { clipboardData , } ) ; if ( this [ Config ] . writeToClipboard ) { await writeDataTransferToClipboard ( doc , clipboardData ) ; } return clipboardData ; }