UNPKG

@vergiss/chooks

Version:
43 lines (38 loc) 1.3 kB
"use strict"; import "core-js/modules/es.object.define-property"; Object.defineProperty(exports, "__esModule", { value: true }); var react_hooks_1 = require("@testing-library/react-hooks"); var index_1 = require("../index"); var mouseMove = function mouseMove(x, y) { react_hooks_1.act(function () { document.dispatchEvent(new MouseEvent('mousemove', { clientX: x, clientY: y, screenX: x, screenY: y })); }); }; describe('useMousePosition', function () { it('should be defined', function () { expect(index_1.useMousePosition).toBeDefined(); }); it('should change the result while mouse moving', function () { var hook = react_hooks_1.renderHook(function () { return index_1.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); }); });