Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { getByTestId } = render(
);
const child = getByTestId("example");
// mouse events
fireEvent.mouseDown(child);
expect(onGrant).toBeCalled();
fireEvent.mouseMove(child);
expect(onMove).toBeCalled();
fireEvent.mouseUp(child);
expect(onRelease).toBeCalled();
// touch events
fireEvent.touchStart(child);
fireEvent.touchMove(child);
fireEvent.touchEnd(child);
expect(onGrant).toBeCalledTimes(2);
expect(onMove).toBeCalledTimes(4);
expect(onRelease).toBeCalledTimes(2);
});
fireEvent.input(htmlEl);
fireEvent.invalid(htmlEl);
fireEvent.submit(htmlEl);
fireEvent.click(htmlEl);
fireEvent.contextMenu(htmlEl);
fireEvent.dblClick(htmlEl);
fireEvent.doubleClick(htmlEl);
fireEvent.drag(htmlEl);
fireEvent.dragEnd(htmlEl);
fireEvent.dragEnter(htmlEl);
fireEvent.dragExit(htmlEl);
fireEvent.dragLeave(htmlEl);
fireEvent.dragOver(htmlEl);
fireEvent.dragStart(htmlEl);
fireEvent.drop(htmlEl);
fireEvent.mouseDown(htmlEl);
fireEvent.mouseEnter(htmlEl);
fireEvent.mouseLeave(htmlEl);
fireEvent.mouseMove(htmlEl);
fireEvent.mouseOut(htmlEl);
fireEvent.mouseOver(htmlEl);
fireEvent.mouseUp(htmlEl);
fireEvent.select(htmlEl);
fireEvent.touchCancel(htmlEl);
fireEvent.touchEnd(htmlEl);
fireEvent.touchMove(htmlEl);
fireEvent.touchStart(htmlEl);
fireEvent.scroll(htmlEl);
fireEvent.wheel(htmlEl);
fireEvent.abort(htmlEl);
fireEvent.canPlay(htmlEl);
fireEvent.canPlayThrough(htmlEl);
test('should close on click away when `closeOnBlur` prop is set to true', () => {
const { button, baseElement, list } = mockDropd({ closeOnBlur: true })
fireEvent.mouseDown(button)
fireEvent.mouseDown(baseElement)
expect(list.classList.contains('open')).toBeFalsy()
})
it("should call the handler when the event is fired", () => {
const handler = jest.fn()
const Component = () => {
const ref = useRef(null)
useEvent("mousedown", ref, handler)
return <div>
}
const { container, rerender } = render()
rerender()
fireEvent.mouseDown(container.firstChild as Element)
expect(handler).toHaveBeenCalledTimes(1)
})
</div>
it("Should not focus onClick", () => {
const { container } = renderTestComponentOne({ disabled: true });
fireEvent.mouseDown(container.querySelector("label"));
expect(container.firstChild).toMatchSnapshot();
});
test('should not close on input mousedown when `closeOnBlur` prop is set to false', () => {
const { button, baseElement, list, inputMock } = mockDropd({
closeOnBlur: false,
})
fireEvent.mouseDown(button)
fireEvent.mouseDown(inputMock)
expect(document.activeElement).toBe(baseElement)
expect(list.classList.contains('open')).toBeTruthy()
})
test('should call the `onOpen` function when it is passed', () => {
const mockFn = jest.fn()
fireEvent.mouseDown(mockDropd({ onOpen: mockFn }).button)
expect(mockFn).toHaveBeenCalledTimes(1)
})
test('should call the `onItemChange` function when it is passed', () => {
const mockFn = jest.fn()
fireEvent.mouseDown(mockDropd({ onItemChange: mockFn }).items[0])
expect(mockFn).toHaveBeenCalledTimes(1)
})
})
onStartShouldSet: () => true,
onMoveShouldSet: () => {
return true;
},
onGrant,
onTerminate: otherTerminate
}}
/>
);
const child = getByTestId("release");
fireEvent.mouseDown(child);
const other = getByTestId("other");
fireEvent.mouseDown(other);
fireEvent.mouseMove(other);
expect(onGrant).toBeCalled();
expect(otherTerminate).toBeCalledTimes(0);
});
const promise = new Promise(resolve => {
const Component = () => {
const ref = useRef(document.body)
useEvent("mousedown", ref, handler)
useEffect(resolve)
return <div>
}
const { rerender, unmount } = render()
rerender()
unmount()
fireEvent.mouseDown(document.body)
})
await expect(promise).resolves.toEqual(undefined)</div>