Skip to content

Commit

Permalink
test: add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiboss committed Oct 24, 2024
1 parent 8b789f3 commit 03915a2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
46 changes: 45 additions & 1 deletion packages/react-use/src/use-element-bounding/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,52 @@
import { describe, expect, it } from 'vitest'
import { renderHook } from '@/test'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { useElementBounding } from './index'

describe('useElementBounding', () => {
let div: HTMLDivElement

beforeEach(() => {
div = document.createElement('div')
div.style.width = '200px'
div.style.height = '100px'
document.body.appendChild(div)
})

afterEach(() => {
div.remove()
})

it('should defined', () => {
expect(useElementBounding).toBeDefined()
})

it('should return initial value', () => {
const { result } = renderHook(() => useElementBounding(null))

expect(result.current[0].x).toBe(0)
expect(result.current[0].y).toBe(0)
expect(result.current[0].width).toBe(0)
expect(result.current[0].height).toBe(0)
expect(result.current[0].left).toBe(0)
expect(result.current[0].top).toBe(0)
expect(result.current[0].right).toBe(0)
expect(result.current[0].bottom).toBe(0)
expect(result.current[1]).toBeInstanceOf(Function)
})

// for now, jsdom/happy-dom not support `MutationObserver`

// it('should return bounding value', () => {
// const { result } = renderHook(() => useElementBounding(div))

// expect(result.current[0].x).toBe(0)
// expect(result.current[0].y).toBe(0)
// expect(result.current[0].width).toBe(0)
// expect(result.current[0].height).toBe(0)
// expect(result.current[0].left).toBe(0)
// expect(result.current[0].top).toBe(0)
// expect(result.current[0].right).toBe(0)
// expect(result.current[0].bottom).toBe(0)
// expect(result.current[1]).toBeInstanceOf(Function)
// })
})
7 changes: 7 additions & 0 deletions packages/react-use/src/use-element-by-point/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { renderHook } from '@/test'
import { describe, expect, it } from 'vitest'
import { useElementByPoint } from './index'

describe('useElementByPoint', () => {
it('should defined', () => {
expect(useElementByPoint).toBeDefined()
})

it('should return initial value', () => {
const { result } = renderHook(() => useElementByPoint({ x: 0, y: 0 }))
expect(result.current.element).toBe(null)
expect(result.current.isSupported).toBe(false)
})
})

0 comments on commit 03915a2

Please sign in to comment.