mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-26 08:19:15 +08:00
[improvement] CountDown: add test cases (#3814)
This commit is contained in:
parent
ed0d053ad7
commit
de5263137d
@ -1,35 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`renders demo correctly 1`] = `
|
||||
<div>
|
||||
<div>
|
||||
<div class="van-count-down">30:00:00</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="van-count-down">01 天 06 时 00 分 00 秒</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="van-count-down">30:00:00:000</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="van-count-down"><span class="item">6</span> <span class="item">0</span> <span class="item">0</span></div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="van-count-down">03:000</div>
|
||||
<div class="van-grid van-hairline--top">
|
||||
<div class="van-grid-item" style="flex-basis: 33.333333333333336%;">
|
||||
<div class="van-grid-item__content van-grid-item__content--center van-grid-item__content--clickable van-hairline"><i class="van-icon van-icon-play-circle-o van-grid-item__icon">
|
||||
<!----></i><span class="van-grid-item__text">开始</span></div>
|
||||
</div>
|
||||
<div class="van-grid-item" style="flex-basis: 33.333333333333336%;">
|
||||
<div class="van-grid-item__content van-grid-item__content--center van-grid-item__content--clickable van-hairline"><i class="van-icon van-icon-pause-circle-o van-grid-item__icon">
|
||||
<!----></i><span class="van-grid-item__text">暂停</span></div>
|
||||
</div>
|
||||
<div class="van-grid-item" style="flex-basis: 33.333333333333336%;">
|
||||
<div class="van-grid-item__content van-grid-item__content--center van-grid-item__content--clickable van-hairline"><i class="van-icon van-icon-replay van-grid-item__icon">
|
||||
<!----></i><span class="van-grid-item__text">重置</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
7
src/count-down/test/__snapshots__/index.spec.js.snap
Normal file
7
src/count-down/test/__snapshots__/index.spec.js.snap
Normal file
@ -0,0 +1,7 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`complete format prop 1`] = `<div class="van-count-down">01-05-59-59-999</div>`;
|
||||
|
||||
exports[`disable auto-start prop 1`] = `<div class="van-count-down">100</div>`;
|
||||
|
||||
exports[`incomplate format prop 1`] = `<div class="van-count-down">29-59-59-999</div>`;
|
@ -1,4 +0,0 @@
|
||||
import Demo from '../demo';
|
||||
import demoTest from '../../../test/demo-test';
|
||||
|
||||
demoTest(Demo);
|
151
src/count-down/test/index.spec.js
Normal file
151
src/count-down/test/index.spec.js
Normal file
@ -0,0 +1,151 @@
|
||||
import CountDown from '..';
|
||||
import { mount, later } from '../../../test/utils';
|
||||
|
||||
test('macro task finish event', async () => {
|
||||
const wrapper = mount(CountDown, {
|
||||
propsData: {
|
||||
time: 1
|
||||
}
|
||||
});
|
||||
|
||||
expect(wrapper.emitted('finish')).toBeFalsy();
|
||||
await later(20);
|
||||
expect(wrapper.emitted('finish')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('micro task finish event', async () => {
|
||||
const wrapper = mount(CountDown, {
|
||||
propsData: {
|
||||
time: 1,
|
||||
millisecond: true
|
||||
}
|
||||
});
|
||||
|
||||
expect(wrapper.emitted('finish')).toBeFalsy();
|
||||
await later(20);
|
||||
expect(wrapper.emitted('finish')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('macro task re-render', async () => {
|
||||
const wrapper = mount(CountDown, {
|
||||
propsData: {
|
||||
time: 1000,
|
||||
format: 'SSS'
|
||||
}
|
||||
});
|
||||
|
||||
const prevSnapShot = wrapper.html();
|
||||
await later(20);
|
||||
const laterSnapShot = wrapper.html();
|
||||
|
||||
expect(prevSnapShot !== laterSnapShot).toBeTruthy();
|
||||
});
|
||||
|
||||
test('micro task re-render', async () => {
|
||||
const wrapper = mount(CountDown, {
|
||||
propsData: {
|
||||
time: 100,
|
||||
format: 'SSS',
|
||||
millisecond: true
|
||||
}
|
||||
});
|
||||
|
||||
const prevSnapShot = wrapper.html();
|
||||
await later(20);
|
||||
const laterSnapShot = wrapper.html();
|
||||
|
||||
expect(prevSnapShot !== laterSnapShot).toBeTruthy();
|
||||
});
|
||||
|
||||
test('disable auto-start prop', async () => {
|
||||
const wrapper = mount(CountDown, {
|
||||
propsData: {
|
||||
time: 100,
|
||||
format: 'SSS',
|
||||
autoStart: false
|
||||
}
|
||||
});
|
||||
|
||||
await later(20);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('start method', async () => {
|
||||
const wrapper = mount(CountDown, {
|
||||
propsData: {
|
||||
time: 100,
|
||||
format: 'SSS',
|
||||
autoStart: false,
|
||||
millisecond: true
|
||||
}
|
||||
});
|
||||
|
||||
const prevSnapShot = wrapper.html();
|
||||
|
||||
wrapper.vm.start();
|
||||
wrapper.vm.start();
|
||||
|
||||
await later(20);
|
||||
|
||||
const laterShapShot = wrapper.html();
|
||||
|
||||
expect(prevSnapShot !== laterShapShot).toBeTruthy();
|
||||
});
|
||||
|
||||
test('pause method', async () => {
|
||||
const wrapper = mount(CountDown, {
|
||||
propsData: {
|
||||
time: 100,
|
||||
format: 'SSS',
|
||||
millisecond: true
|
||||
}
|
||||
});
|
||||
|
||||
const prevSnapShot = wrapper.html();
|
||||
wrapper.vm.pause();
|
||||
await later(20);
|
||||
const laterShapShot = wrapper.html();
|
||||
|
||||
expect(prevSnapShot === laterShapShot).toBeTruthy();
|
||||
});
|
||||
|
||||
test('reset method', async () => {
|
||||
const wrapper = mount(CountDown, {
|
||||
propsData: {
|
||||
time: 100,
|
||||
format: 'SSS',
|
||||
millisecond: true
|
||||
}
|
||||
});
|
||||
|
||||
const prevSnapShot = wrapper.html();
|
||||
await later(20);
|
||||
wrapper.vm.reset();
|
||||
const laterShapShot = wrapper.html();
|
||||
|
||||
expect(prevSnapShot === laterShapShot).toBeTruthy();
|
||||
});
|
||||
|
||||
test('complete format prop', () => {
|
||||
const wrapper = mount(CountDown, {
|
||||
propsData: {
|
||||
time: 30 * 60 * 60 * 1000 - 1,
|
||||
autoStart: false,
|
||||
format: 'DD-HH-mm-ss-SSS'
|
||||
}
|
||||
});
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('incomplate format prop', () => {
|
||||
const wrapper = mount(CountDown, {
|
||||
propsData: {
|
||||
time: 30 * 60 * 60 * 1000 - 1,
|
||||
autoStart: false,
|
||||
format: 'HH-mm-ss-SSS'
|
||||
}
|
||||
});
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user