Skip to content

Commit

Permalink
reduce some code deps
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisBrunner committed Dec 12, 2024
1 parent 079c0fd commit 59545ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
52 changes: 16 additions & 36 deletions packages/react-dnd-preview/src/__tests__/usePreview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>(null))
Expand Down Expand Up @@ -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
Expand All @@ -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}
},
Expand Down Expand Up @@ -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}
},
Expand Down Expand Up @@ -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}
},
Expand Down

0 comments on commit 59545ef

Please sign in to comment.