UNPKG

@wojtekmaj/react-hooks

Version:

A collection of React Hooks.

22 lines (15 loc) 680 B
import { describe, expect, it } from 'vitest'; import { renderHook } from '@testing-library/react'; import useWindowWidth from './useWindowWidth.js'; const itIfWindowDefined = it.runIf(typeof window !== 'undefined'); const itIfWindowUndefined = it.runIf(typeof window === 'undefined'); describe('useWindowWidth()', () => { itIfWindowDefined('should return window.innerWidth by default', () => { const { result } = renderHook(() => useWindowWidth()); expect(result.current).toBe(window.innerWidth); }); itIfWindowUndefined('should return null', () => { const { result } = renderHook(() => useWindowWidth()); expect(result.current).toBe(null); }); });