2020-07-02 10:46:47 +08:00
|
|
|
import ResponsiveObserve, { responsiveMap } from '../responsiveObserve';
|
|
|
|
|
|
|
|
describe('Test ResponsiveObserve', () => {
|
|
|
|
it('test ResponsiveObserve subscribe and unsubscribe', () => {
|
|
|
|
const { xs } = responsiveMap;
|
|
|
|
const subscribeFunc = jest.fn();
|
|
|
|
const token = ResponsiveObserve.subscribe(subscribeFunc);
|
|
|
|
expect(ResponsiveObserve.matchHandlers[xs].mql.matches).toBeTruthy();
|
2022-08-30 10:57:13 +08:00
|
|
|
expect(subscribeFunc).toHaveBeenCalledTimes(1);
|
2020-07-02 10:46:47 +08:00
|
|
|
|
|
|
|
ResponsiveObserve.unsubscribe(token);
|
2022-08-30 10:57:13 +08:00
|
|
|
expect(ResponsiveObserve.matchHandlers[xs].mql.removeListener).toHaveBeenCalled();
|
2020-07-02 10:46:47 +08:00
|
|
|
});
|
|
|
|
});
|