afc163
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
7 additions and
7 deletions
-
components/spin/__tests__/delay.test.js
-
components/spin/__tests__/index.test.js
-
components/spin/index.tsx
|
|
@ -1,7 +1,7 @@ |
|
|
|
import React from 'react'; |
|
|
|
import { mount } from 'enzyme'; |
|
|
|
// eslint-disable-next-line import/no-named-as-default
|
|
|
|
import Spin, { Spin as SpinClass } from '..'; |
|
|
|
import Spin from '..'; |
|
|
|
import { sleep } from '../../../tests/utils'; |
|
|
|
|
|
|
|
describe('delay spinning', () => { |
|
|
@ -25,8 +25,8 @@ describe('delay spinning', () => { |
|
|
|
|
|
|
|
it('should cancel debounce function when unmount', async () => { |
|
|
|
const wrapper = mount(<Spin spinning delay={100} />); |
|
|
|
const spy = jest.spyOn(wrapper.find(SpinClass).instance().updateSpinning, 'cancel'); |
|
|
|
expect(wrapper.find(SpinClass).instance().updateSpinning.cancel).toEqual(expect.any(Function)); |
|
|
|
const spy = jest.spyOn(wrapper.find(Spin).instance().updateSpinning, 'cancel'); |
|
|
|
expect(wrapper.find(Spin).instance().updateSpinning.cancel).toEqual(expect.any(Function)); |
|
|
|
expect(spy).not.toHaveBeenCalled(); |
|
|
|
wrapper.unmount(); |
|
|
|
expect(spy).toHaveBeenCalled(); |
|
|
|
|
|
@ -1,7 +1,7 @@ |
|
|
|
import React from 'react'; |
|
|
|
import { render, mount } from 'enzyme'; |
|
|
|
// eslint-disable-next-line import/no-named-as-default
|
|
|
|
import Spin, { Spin as SpinClass } from '..'; |
|
|
|
import Spin from '..'; |
|
|
|
import mountTest from '../../../tests/shared/mountTest'; |
|
|
|
import rtlTest from '../../../tests/shared/rtlTest'; |
|
|
|
|
|
|
@ -27,9 +27,9 @@ describe('Spin', () => { |
|
|
|
|
|
|
|
it('should be controlled by spinning', () => { |
|
|
|
const wrapper = mount(<Spin spinning={false} />); |
|
|
|
expect(wrapper.find(SpinClass).instance().state.spinning).toBe(false); |
|
|
|
expect(wrapper.find(Spin).instance().state.spinning).toBe(false); |
|
|
|
wrapper.setProps({ spinning: true }); |
|
|
|
expect(wrapper.find(SpinClass).instance().state.spinning).toBe(true); |
|
|
|
expect(wrapper.find(Spin).instance().state.spinning).toBe(true); |
|
|
|
}); |
|
|
|
|
|
|
|
it('if indicator set null should not be render default indicator', () => { |
|
|
|
|
|
@ -76,7 +76,7 @@ function shouldDelay(spinning?: boolean, delay?: number): boolean { |
|
|
|
return !!spinning && !!delay && !isNaN(Number(delay)); |
|
|
|
} |
|
|
|
|
|
|
|
export class Spin extends React.Component<SpinClassProps, SpinState> { |
|
|
|
class Spin extends React.Component<SpinClassProps, SpinState> { |
|
|
|
static defaultProps = { |
|
|
|
spinning: true, |
|
|
|
size: 'default' as SpinSize, |
|
|
|