mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-13 15:49:10 +08:00
7322aa6f5f
This reverts commit 6759887c44
.
27 lines
930 B
TypeScript
27 lines
930 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();
|
|
});
|
|
});
|