forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
142 lines (133 loc) · 3.74 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { mount } from '@vue/test-utils';
import { h, createVNode } from 'vue';
import { asyncExpect, sleep } from '../../../tests/utils';
import Carousel from '..';
import mountTest from '../../../tests/shared/mountTest';
describe('Carousel', () => {
mountTest(Carousel);
// beforeEach(() => {
// jest.useFakeTimers();
// });
// afterEach(() => {
// jest.useRealTimers();
// });
it('should has innerSlider', () => {
const props = {
slots: {
default: () => h('div'),
},
sync: false,
};
const wrapper = mount(Carousel, props);
const { innerSlider } = wrapper.componentVM;
expect(typeof innerSlider.slickNext).toBe('function');
});
it('should has prev, next and go function', async () => {
const props = {
slots: {
default: () => [
createVNode('div', null, '1'),
createVNode('div', null, '2'),
createVNode('div', null, '3'),
],
},
sync: false,
};
const wrapper = mount(Carousel, props);
const { prev, next, goTo, innerSlider } = wrapper.componentVM;
expect(typeof prev).toBe('function');
expect(typeof next).toBe('function');
expect(typeof goTo).toBe('function');
expect(innerSlider.currentSlide).toBe(0);
wrapper.vm.goTo(2);
await asyncExpect(() => {
expect(innerSlider.currentSlide).toBe(2);
}, 1000);
prev();
await asyncExpect(() => {
expect(innerSlider.currentSlide).toBe(1);
}, 1000);
next();
await asyncExpect(() => {
expect(innerSlider.currentSlide).toBe(2);
}, 1000);
});
// TODO
// it('should trigger autoPlay after window resize', async () => {
// const props = {
// props: {
// autoplay: true,
// },
// slots: {
// default: () => [
// createVNode('div', null, '1'),
// createVNode('div', null, '2'),
// createVNode('div', null, '3'),
// ],
// },
// sync: false,
// };
// const wrapper = mount(Carousel, props);
// await sleep(100);
// const spy = jest.spyOn(wrapper.componentVM.innerSlider, 'handleAutoPlay');
// window.resizeTo(1000);
// expect(spy).not.toHaveBeenCalled();
// await new Promise(resolve => setTimeout(resolve, 1000));
// expect(spy).toHaveBeenCalled();
// });
it('cancel resize listener when unmount', async () => {
const props = {
props: {
autoplay: true,
},
slots: {
default: () => [
createVNode('div', null, '1'),
createVNode('div', null, '2'),
createVNode('div', null, '3'),
],
},
sync: false,
};
const wrapper = mount(Carousel, props);
const spy = jest.spyOn(window, 'removeEventListener');
wrapper.unmount();
expect(spy).toHaveBeenCalled();
});
describe('should works for dotPosition', () => {
['left', 'right', 'top', 'bottom'].forEach(dotPosition => {
it(dotPosition, async () => {
const wrapper = mount(
{
render() {
return (
<Carousel dotPosition={dotPosition}>
<div />
</Carousel>
);
},
},
{ sync: false, attachTo: 'body' },
);
await sleep(100);
expect(wrapper.html()).toMatchSnapshot();
});
});
});
it('warning', () => {
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
mount({
render() {
return (
<Carousel vertical>
<div />
</Carousel>
);
},
});
expect(warnSpy).toHaveBeenCalledWith(
'Warning: [ant-design-vue: Carousel] `vertical` is deprecated, please use `dotPosition` instead.',
);
warnSpy.mockRestore();
});
});