mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-08 01:53:34 +08:00

* 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>
25 lines
884 B
TypeScript
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();
|
|
});
|
|
});
|