feat: add unit tests and CI configuration
This commit is contained in:
34
lib/hooks/__tests__/useOnlineStatus.test.ts
Normal file
34
lib/hooks/__tests__/useOnlineStatus.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { renderHook, act } from '@testing-library/react'
|
||||
import { useOnlineStatus } from '../useOnlineStatus'
|
||||
|
||||
describe('useOnlineStatus', () => {
|
||||
it('returns true initially', () => {
|
||||
const { result } = renderHook(() => useOnlineStatus())
|
||||
expect(result.current).toBe(true)
|
||||
})
|
||||
|
||||
it('returns false when offline event fires', () => {
|
||||
const { result } = renderHook(() => useOnlineStatus())
|
||||
|
||||
act(() => {
|
||||
window.dispatchEvent(new Event('offline'))
|
||||
})
|
||||
|
||||
expect(result.current).toBe(false)
|
||||
})
|
||||
|
||||
it('returns true when online event fires after offline', () => {
|
||||
const { result } = renderHook(() => useOnlineStatus())
|
||||
|
||||
act(() => {
|
||||
window.dispatchEvent(new Event('offline'))
|
||||
})
|
||||
expect(result.current).toBe(false)
|
||||
|
||||
act(() => {
|
||||
window.dispatchEvent(new Event('online'))
|
||||
})
|
||||
expect(result.current).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user