ant-design/ant-design

View on GitHub
components/_util/__tests__/responsiveObserve.test.tsx

Summary

Maintainability
A
0 mins
Test Coverage
import React from 'react';

import { render } from '../../../tests/utils';
import useResponsiveObserver from '../responsiveObserver';

describe('Test ResponsiveObserve', () => {
  it('test ResponsiveObserve subscribe and unsubscribe', () => {
    let responsiveObserveRef: any;
    const Demo = () => {
      const responsiveObserver = useResponsiveObserver();
      responsiveObserveRef = responsiveObserver;
      return null;
    };
    render(<Demo />);
    const subscribeFunc = jest.fn();
    const token = responsiveObserveRef.subscribe(subscribeFunc);
    expect(
      responsiveObserveRef.matchHandlers[responsiveObserveRef.responsiveMap.xs].mql.matches,
    ).toBeTruthy();
    expect(subscribeFunc).toHaveBeenCalledTimes(1);

    responsiveObserveRef.unsubscribe(token);
    expect(
      responsiveObserveRef.matchHandlers[responsiveObserveRef.responsiveMap.xs].mql.removeListener,
    ).toHaveBeenCalled();
  });
});