From b129e05630234924c539af12b8b6799bfaa92886 Mon Sep 17 00:00:00 2001 From: zombieJ Date: Sat, 5 Jan 2019 17:13:42 +0800 Subject: [PATCH] init Spin should also support delay trigger (#14105) fix #14100 --- components/spin/__tests__/index.test.js | 47 ++++++++++++++++++++----- components/spin/index.tsx | 4 +++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/components/spin/__tests__/index.test.js b/components/spin/__tests__/index.test.js index 69170b498c..633f3057f0 100644 --- a/components/spin/__tests__/index.test.js +++ b/components/spin/__tests__/index.test.js @@ -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(); - 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(); + expect( + wrapper + .find('.ant-spin') + .at(0) + .hasClass('ant-spin-spinning'), + ).toEqual(false); + }); + + it('should render when delay is init set', () => { + const wrapper = mount(); + + 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', () => { diff --git a/components/spin/index.tsx b/components/spin/index.tsx index 56eab0393f..73af02007b 100644 --- a/components/spin/index.tsx +++ b/components/spin/index.tsx @@ -94,6 +94,10 @@ class Spin extends React.Component { return !!(this.props && this.props.children); } + componentDidMount() { + this.componentDidUpdate(); + } + componentWillUnmount() { if (this.debounceTimeout) { clearTimeout(this.debounceTimeout);