docbrown/app/javascript/utilities/__tests__/pasteImage.test.js
Andrew Bone 9ef1534d83
Add paste image (#10212)
Co-authored-by: Nick Taylor <nick@iamdeveloper.com>
Co-authored-by: ludwiczakpawel <ludwiczakpawel@gmail.com>
Co-authored-by: Nick Taylor <nick@dev.to>
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
2021-02-04 10:58:56 -05:00

25 lines
724 B
JavaScript

import { renderHook, act } from '@testing-library/preact-hooks';
import { fireEvent } from '@testing-library/preact';
import { usePasteImage } from '../pasteImage';
describe('usePasteImage', () => {
it('listens for paste events on the set element', () => {
const handlePasteImage = jest.fn();
document.body.innerHTML = `
<div id="paste-area"></div>
`;
const element = document.getElementById('paste-area');
const {
result: { current: setElement },
} = renderHook(() => usePasteImage({ onPaste: handlePasteImage }));
act(() => {
setElement(element);
});
fireEvent.paste(element, { clipboardData: {} });
expect(handlePasteImage).toHaveBeenCalled();
});
});