2019-01-05 12:23:20 +08:00
|
|
|
import React from 'react';
|
2019-01-07 10:25:23 +08:00
|
|
|
import { mount } from 'enzyme';
|
2022-03-25 14:26:09 +08:00
|
|
|
// eslint-disable-next-line import/no-named-as-default
|
|
|
|
import Spin, { Spin as SpinClass } from '..';
|
2021-11-26 12:18:21 +08:00
|
|
|
import { sleep } from '../../../tests/utils';
|
2019-01-05 12:23:20 +08:00
|
|
|
|
|
|
|
describe('delay spinning', () => {
|
2019-01-13 21:18:38 +08:00
|
|
|
it("should render with delay when it's mounted with spinning=true and delay", () => {
|
2019-01-07 10:25:23 +08:00
|
|
|
const wrapper = mount(<Spin spinning delay={500} />);
|
2020-10-21 10:35:06 +08:00
|
|
|
expect(wrapper.find('.ant-spin').at(0).hasClass('ant-spin-spinning')).toEqual(false);
|
2019-01-05 12:23:20 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render when delay is init set', async () => {
|
|
|
|
const wrapper = mount(<Spin spinning delay={100} />);
|
|
|
|
|
2020-10-21 10:35:06 +08:00
|
|
|
expect(wrapper.find('.ant-spin').at(0).hasClass('ant-spin-spinning')).toEqual(false);
|
2019-01-05 12:23:20 +08:00
|
|
|
|
|
|
|
// use await not jest.runAllTimers()
|
|
|
|
// because of https://github.com/facebook/jest/issues/3465
|
2021-11-26 12:18:21 +08:00
|
|
|
await sleep(500);
|
2019-01-05 12:23:20 +08:00
|
|
|
wrapper.update();
|
|
|
|
|
2020-10-21 10:35:06 +08:00
|
|
|
expect(wrapper.find('.ant-spin').at(0).hasClass('ant-spin-spinning')).toEqual(true);
|
2019-01-05 12:23:20 +08:00
|
|
|
});
|
2019-01-07 14:21:57 +08:00
|
|
|
|
|
|
|
it('should cancel debounce function when unmount', async () => {
|
|
|
|
const wrapper = mount(<Spin spinning delay={100} />);
|
2022-03-25 14:26:09 +08:00
|
|
|
const spy = jest.spyOn(wrapper.find(SpinClass).instance().updateSpinning, 'cancel');
|
|
|
|
expect(wrapper.find(SpinClass).instance().updateSpinning.cancel).toEqual(expect.any(Function));
|
2019-01-07 14:21:57 +08:00
|
|
|
expect(spy).not.toHaveBeenCalled();
|
|
|
|
wrapper.unmount();
|
|
|
|
expect(spy).toHaveBeenCalled();
|
|
|
|
});
|
2019-01-05 12:23:20 +08:00
|
|
|
});
|