Skip to content

Commit

Permalink
format:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
satelllte committed May 9, 2024
1 parent 47c5669 commit 3380381
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions packages/fiber/tests/core/events.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,16 @@ describe('events', () => {
const handlePointerLeave = jest.fn()

/* This component lets us unmount the event-handling object */
function PointerCaptureTest(props: { hasMesh: boolean, manualRelease?: boolean }) {
function PointerCaptureTest(props: { hasMesh: boolean; manualRelease?: boolean }) {
return (
<Canvas>
{props.hasMesh && (
<mesh onPointerDown={handlePointerDown} onPointerMove={handlePointerMove} onPointerUp={props.manualRelease ? handlePointerUp : undefined} onPointerLeave={handlePointerLeave} onPointerEnter={handlePointerEnter}>
<mesh
onPointerDown={handlePointerDown}
onPointerMove={handlePointerMove}
onPointerUp={props.manualRelease ? handlePointerUp : undefined}
onPointerLeave={handlePointerLeave}
onPointerEnter={handlePointerEnter}>
<boxGeometry args={[2, 2]} />
<meshBasicMaterial />
</mesh>
Expand Down Expand Up @@ -350,9 +355,9 @@ describe('events', () => {

/* testing-utils/react's fireEvent wraps the event like React does, so it doesn't match how our event handlers are called in production, so we call dispatchEvent directly. */
await act(async () => canvas.dispatchEvent(moveIn))
expect(handlePointerEnter).toHaveBeenCalledTimes(1);
expect(handlePointerMove).toHaveBeenCalledTimes(1);
expect(handlePointerEnter).toHaveBeenCalledTimes(1)
expect(handlePointerMove).toHaveBeenCalledTimes(1)

const down = new PointerEvent('pointerdown', { pointerId })
Object.defineProperty(down, 'offsetX', { get: () => 577 })
Object.defineProperty(down, 'offsetY', { get: () => 480 })
Expand All @@ -362,11 +367,11 @@ describe('events', () => {
// If we move the pointer now, when it is captured, it should raise the onPointerMove event even though the pointer is not over the element,
// and NOT raise the onPointerLeave event.
await act(async () => canvas.dispatchEvent(moveOut))
expect(handlePointerMove).toHaveBeenCalledTimes(2);
expect(handlePointerLeave).not.toHaveBeenCalled();
expect(handlePointerMove).toHaveBeenCalledTimes(2)
expect(handlePointerLeave).not.toHaveBeenCalled()

await act(async () => canvas.dispatchEvent(moveIn))
expect(handlePointerMove).toHaveBeenCalledTimes(3);
expect(handlePointerMove).toHaveBeenCalledTimes(3)

const up = new PointerEvent('pointerup', { pointerId })
Object.defineProperty(up, 'offsetX', { get: () => 577 })
Expand All @@ -377,11 +382,11 @@ describe('events', () => {
await act(async () => canvas.dispatchEvent(lostpointercapture))

// The pointer is still over the element, so onPointerLeave should not have been called.
expect(handlePointerLeave).not.toHaveBeenCalled();
expect(handlePointerLeave).not.toHaveBeenCalled()

// The element pointer should no longer be captured, so moving it away should call onPointerLeave.
await act(async () => canvas.dispatchEvent(moveOut));
expect(handlePointerEnter).toHaveBeenCalledTimes(1);
await act(async () => canvas.dispatchEvent(moveOut))
expect(handlePointerEnter).toHaveBeenCalledTimes(1)
expect(handlePointerLeave).toHaveBeenCalledTimes(1)
})
})
Expand Down

0 comments on commit 3380381

Please sign in to comment.