From 59545ef873fc580b2c5b437962b565ab7b9a3a67 Mon Sep 17 00:00:00 2001 From: Louis Brunner Date: Thu, 12 Dec 2024 17:06:21 +0000 Subject: [PATCH] reduce some code deps --- .../src/hooks/__tests__/useMultiDrag.test.tsx | 11 +--- .../src/hooks/__tests__/useMultiDrop.test.tsx | 11 +--- .../src/__tests__/usePreview.test.ts | 52 ++++++------------- 3 files changed, 20 insertions(+), 54 deletions(-) diff --git a/packages/react-dnd-multi-backend/src/hooks/__tests__/useMultiDrag.test.tsx b/packages/react-dnd-multi-backend/src/hooks/__tests__/useMultiDrag.test.tsx index 58ba9bd..119f6ad 100644 --- a/packages/react-dnd-multi-backend/src/hooks/__tests__/useMultiDrag.test.tsx +++ b/packages/react-dnd-multi-backend/src/hooks/__tests__/useMultiDrag.test.tsx @@ -18,17 +18,10 @@ describe('useMultiDrag component', () => { } test('fails without a context', () => { - let err: Error | undefined const spy = jest.spyOn(console, 'error') spy.mockImplementation(() => {}) - try { - renderHook(MultiAction) - } catch (e) { - err = e as Error - } finally { - spy.mockRestore() - expect(err).toEqual(expect.any(Error)) - } + expect(() => renderHook(MultiAction)).toThrow() + spy.mockRestore() }) test('it works', () => { diff --git a/packages/react-dnd-multi-backend/src/hooks/__tests__/useMultiDrop.test.tsx b/packages/react-dnd-multi-backend/src/hooks/__tests__/useMultiDrop.test.tsx index 35aa59e..aa4e881 100644 --- a/packages/react-dnd-multi-backend/src/hooks/__tests__/useMultiDrop.test.tsx +++ b/packages/react-dnd-multi-backend/src/hooks/__tests__/useMultiDrop.test.tsx @@ -19,17 +19,10 @@ describe('useMultiDrop component', () => { } test('fails without a context', () => { - let err: Error | undefined const spy = jest.spyOn(console, 'error') spy.mockImplementation(() => {}) - try { - renderHook(MultiAction) - } catch (e) { - err = e as Error - } finally { - spy.mockRestore() - expect(err).toEqual(expect.any(Error)) - } + expect(() => renderHook(MultiAction)).toThrow() + spy.mockRestore() }) test('it works', () => { diff --git a/packages/react-dnd-preview/src/__tests__/usePreview.test.ts b/packages/react-dnd-preview/src/__tests__/usePreview.test.ts index 026de1f..7067c35 100644 --- a/packages/react-dnd-preview/src/__tests__/usePreview.test.ts +++ b/packages/react-dnd-preview/src/__tests__/usePreview.test.ts @@ -5,6 +5,18 @@ import type {MutableRefObject} from 'react' import type {PreviewPlacement} from '../offsets' import {usePreview, type usePreviewStateFull} from '../usePreview' +const DraggingMonitor = { + isDragging() { + return true + }, + getItemType() { + return 'no' + }, + getClientOffset() { + return {x: 1, y: 2} + }, +} + describe('usePreview hook', () => { beforeEach(() => { __setMockMonitor(MockDragMonitor(null)) @@ -59,15 +71,7 @@ describe('usePreview hook', () => { test('return true and data when DnD is in progress', () => { __setMockMonitor({ ...MockDragMonitor<{bluh: string}>({bluh: 'fake'}), - isDragging() { - return true - }, - getItemType() { - return 'no' - }, - getClientOffset() { - return {x: 1, y: 2} - }, + ...DraggingMonitor, }) const {result} = renderHook(() => { return usePreview() as usePreviewStateFull @@ -94,15 +98,7 @@ describe('usePreview hook', () => { test('return true and data when DnD is in progress (with parent offset)', () => { __setMockMonitor({ ...MockDragMonitor<{bluh: string}>({bluh: 'fake'}), - isDragging() { - return true - }, - getItemType() { - return 'no' - }, - getClientOffset() { - return {x: 1, y: 2} - }, + ...DraggingMonitor, getInitialClientOffset() { return {x: 1, y: 2} }, @@ -135,15 +131,7 @@ describe('usePreview hook', () => { test('return true and data when DnD is in progress (with ref)', async () => { __setMockMonitor({ ...MockDragMonitor<{bluh: string}>({bluh: 'fake'}), - isDragging() { - return true - }, - getItemType() { - return 'no' - }, - getClientOffset() { - return {x: 1, y: 2} - }, + ...DraggingMonitor, getInitialClientOffset() { return {x: 1, y: 2} }, @@ -250,15 +238,7 @@ describe('usePreview hook', () => { test.each(cases)('return true and data when DnD is in progress (with ref, parent offset and placement $placement)', async ({placement, expectedTransform}) => { __setMockMonitor({ ...MockDragMonitor<{bluh: string}>({bluh: 'fake'}), - isDragging() { - return true - }, - getItemType() { - return 'no' - }, - getClientOffset() { - return {x: 1, y: 2} - }, + ...DraggingMonitor, getInitialClientOffset() { return {x: 1, y: 2} },