init Spin should also support delay trigger (#14105)

fix #14100
This commit is contained in:
zombieJ 2019-01-05 17:13:42 +08:00 committed by Junbin Huang
parent 059670a09e
commit b129e05630
2 changed files with 43 additions and 8 deletions

View File

@ -29,14 +29,45 @@ describe('Spin', () => {
expect(wrapper).toMatchSnapshot();
});
it("should render with delay when it's mounted with spinning=true and delay", () => {
const wrapper = shallow(<Spin spinning delay={500} />);
expect(
wrapper
.find('.ant-spin')
.at(0)
.hasClass('ant-spin-spinning'),
).toEqual(false);
describe('delay spinning', () => {
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.useRealTimers();
});
it("should render with delay when it's mounted with spinning=true and delay", () => {
const wrapper = shallow(<Spin spinning delay={500} />);
expect(
wrapper
.find('.ant-spin')
.at(0)
.hasClass('ant-spin-spinning'),
).toEqual(false);
});
it('should render when delay is init set', () => {
const wrapper = mount(<Spin spinning delay={100} />);
expect(
wrapper
.find('.ant-spin')
.at(0)
.hasClass('ant-spin-spinning'),
).toEqual(false);
jest.runAllTimers();
wrapper.update();
expect(
wrapper
.find('.ant-spin')
.at(0)
.hasClass('ant-spin-spinning'),
).toEqual(true);
});
});
it('should be controlled by spinning', () => {

View File

@ -94,6 +94,10 @@ class Spin extends React.Component<SpinProps, SpinState> {
return !!(this.props && this.props.children);
}
componentDidMount() {
this.componentDidUpdate();
}
componentWillUnmount() {
if (this.debounceTimeout) {
clearTimeout(this.debounceTimeout);