mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-15 09:21:22 +08:00
328a800132
Rename useResponsiveObserve to useResponsiveObserver. Add validation of breakpoints values and test
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();
|
|
});
|
|
});
|