/* eslint-disable react/no-children-prop */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { useContext } from 'react'; import { render } from '@testing-library/react'; import { MatchMediaBreakpoints as ReactBreakpoints } from '../MatchMediaBreakpoints'; import { BreakpointsContext } from '../BreakpointsContext'; import { BreakpointsProps } from '../breakpoints'; describe('MatchMediaBreakpoints', function () { const propsMock = jest.fn(); function propsMockResult() { return propsMock.mock.results.map(v => v.value); } function Children({ text = '' }: { text?: string }) { const props = useContext(BreakpointsContext); propsMock(props); return
{text}
; } beforeEach(() => { propsMock.mockClear(); propsMock.mockImplementation((props: BreakpointsProps) => { return props; }); jest.spyOn(console, 'error').mockImplementation(() => { /* linter */ }); }); it('explodes if there are no breakpoints', function () { expect(() => render( } />, ), ).toThrow(); expect(() => render( } />, ), ).toThrow(); expect(() => render(} />), ).toThrow(); }); it('passed breakpoints through context', function () { const breakpoints = { mobile: 320, tablet: 768, desktop: 1200, }; render( } />, ); expect(propsMockResult()).toMatchObject([{ breakpoints }]); }); it('renders its children', function () { const result = render( } />, ); expect(result.findByTestId('children')).resolves.toBeDefined(); }); it('works with unit em', function () { const result = render( } />, ); expect(result.findByTestId('children')).resolves.toBeDefined(); }); });