Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/usehooks-ts/src/useMediaQuery/useMediaQuery.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { renderHook } from '@testing-library/react'

import { mockMatchMedia } from '../../tests/mocks'
import { useMediaQuery } from './useMediaQuery'

describe('useMediaQuery()', () => {
// TODO: currently don't know how to simulate hydration of hooks. @see https://github.com/testing-library/react-testing-library/issues/1120
it.skip('should return true during SSR when defaultValue is true', () => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add ssr test case but there is an issue according to #302 (comment)

so i decied add skip and add todo tag

mockMatchMedia(false)
const { result } = renderHook(() =>
useMediaQuery('(max-width: 600px)', {
defaultValue: true,
initializeWithValue: false,
}),
)
expect(result.current).toBeTruthy()
})

it('should return true when matchMedia matches', () => {
mockMatchMedia(true)
const { result } = renderHook(() => useMediaQuery('(max-width: 600px)'))
expect(result.current).toBeTruthy()
})

it('should return false when matchMedia does not match', () => {
mockMatchMedia(false)
const { result } = renderHook(() => useMediaQuery('(max-width: 600px)'))
expect(result.current).toBeFalsy()
})
})