@vergiss/chooks
Version:
React hooks library
35 lines (33 loc) • 1.14 kB
JavaScript
import { act, renderHook } from '@testing-library/react-hooks';
import { useMousePosition } from '../index';
var mouseMove = function mouseMove(x, y) {
act(function () {
document.dispatchEvent(new MouseEvent('mousemove', {
clientX: x,
clientY: y,
screenX: x,
screenY: y
}));
});
};
describe('useMousePosition', function () {
it('should be defined', function () {
expect(useMousePosition).toBeDefined();
});
it('should change the result while mouse moving', function () {
var hook = renderHook(function () {
return useMousePosition();
});
expect(hook.result.current.pageX).toBe(NaN);
expect(hook.result.current.pageY).toBe(NaN);
expect(hook.result.current.clientX).toBe(NaN);
expect(hook.result.current.clientY).toBe(NaN);
expect(hook.result.current.screenX).toBe(NaN);
expect(hook.result.current.screenY).toBe(NaN);
mouseMove(100, 200);
expect(hook.result.current.clientX).toBe(100);
expect(hook.result.current.clientY).toBe(200);
expect(hook.result.current.screenX).toBe(100);
expect(hook.result.current.screenY).toBe(200);
});
});