ant-design-vue/components/spin/__tests__/delay.test.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-09-18 12:03:13 +00:00
import { mount } from '@vue/test-utils';
import { asyncExpect } from '@/tests/utils';
import Spin from '..';
describe('delay spinning', () => {
it("should render with delay when it's mounted with spinning=true and delay", async () => {
const props = {
2020-07-25 07:46:49 +00:00
props: {
2019-09-18 12:03:13 +00:00
delay: 500,
spinning: true,
},
sync: false,
};
const wrapper = mount(Spin, props);
await asyncExpect(() => {
2021-06-23 15:08:16 +00:00
expect(wrapper.find('.ant-spin').classes().includes('ant-spin-spinning')).toEqual(false);
2019-09-18 12:03:13 +00:00
});
});
it('should render when delay is init set', async () => {
const props = {
2020-07-25 07:46:49 +00:00
props: {
2019-09-18 12:03:13 +00:00
delay: 100,
spinning: true,
},
sync: false,
};
const wrapper = mount(Spin, props);
2021-06-23 15:08:16 +00:00
expect(wrapper.findAll('.ant-spin')[0].classes().includes('ant-spin-spinning')).toEqual(false);
2019-09-18 12:03:13 +00:00
// use await not jest.runAllTimers()
// because of https://github.com/facebook/jest/issues/3465
await new Promise(resolve => setTimeout(resolve, 500));
2021-06-23 15:08:16 +00:00
expect(wrapper.findAll('.ant-spin')[0].classes().includes('ant-spin-spinning')).toEqual(true);
2019-09-18 12:03:13 +00:00
});
it('should cancel debounce function when unmount', async () => {
const props = {
2020-07-25 07:46:49 +00:00
props: {
2019-09-18 12:03:13 +00:00
delay: 100,
spinning: true,
},
sync: false,
};
const wrapper = mount(Spin, props);
const spy = jest.spyOn(wrapper.vm.updateSpinning, 'cancel');
expect(wrapper.vm.updateSpinning.cancel).toEqual(expect.any(Function));
expect(spy).not.toHaveBeenCalled();
});
});