ant-design/components/_util/__tests__/responsiveObserve.test.tsx
lijianan b340b3ad0d
refactor: optimization compatible logic (#53107)
* refactor: optimization compatible logic

* test: fix test case

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

* fix: fix

---------

Signed-off-by: lijianan <574980606@qq.com>
Co-authored-by: afc163 <afc163@gmail.com>
2025-03-24 10:24:12 +08:00

25 lines
884 B
TypeScript

import React from 'react';
import { render } from '../../../tests/utils';
import useResponsiveObserver from '../responsiveObserver';
describe('Test ResponsiveObserve', () => {
it('test ResponsiveObserve subscribe and unsubscribe', () => {
let responsiveRef: any = null;
const Demo: React.FC = () => {
const responsiveObserver = useResponsiveObserver();
responsiveRef = responsiveObserver;
return null;
};
render(<Demo />);
const subscribeFunc = jest.fn();
const token = responsiveRef.subscribe(subscribeFunc);
expect(responsiveRef.matchHandlers[responsiveRef.responsiveMap.xs].mql.matches).toBeTruthy();
expect(subscribeFunc).toHaveBeenCalledTimes(1);
responsiveRef.unsubscribe(token);
expect(
responsiveRef.matchHandlers[responsiveRef.responsiveMap.xs].mql?.removeEventListener,
).toHaveBeenCalled();
});
});