import { renderHook } from '@testing-library/react';

import { mockMatchMedia } from '../../test-utils/window-mock';

import { useMedia } from './useMedia';

mockMatchMedia();

describe('useMedia', () => {
  it('tracks changes of window size', () => {
    const { result, rerender } = renderHook(() => useMedia('(min-width: 1024px)'));

    window.innerWidth = 1920;
    rerender();
    expect(result.current).toBeTruthy();

    window.innerWidth = 1024;
    rerender();
    expect(result.current).toBeTruthy();

    window.innerWidth = 800;
    rerender();
    expect(result.current).toBeFalsy();
  });
});
