mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-04 00:49:39 +08:00
502dac12aa
* docs: fix code * feat: lint * feat: prettier * feat: test * feat: review * feat: format html * feat: format html
28 lines
931 B
TypeScript
28 lines
931 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 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();
|
|
});
|
|
});
|