mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[Improvement] Toast: add test cases (#1104)
This commit is contained in:
parent
bb74fd0bd5
commit
3d669b4a81
@ -125,6 +125,7 @@
|
|||||||
"!**/demo/**",
|
"!**/demo/**",
|
||||||
"!**/locale/lang/**",
|
"!**/locale/lang/**",
|
||||||
"!**/waterfall/**",
|
"!**/waterfall/**",
|
||||||
|
"!**/sku/**",
|
||||||
"!**/lazyload/**"
|
"!**/lazyload/**"
|
||||||
],
|
],
|
||||||
"collectCoverage": true,
|
"collectCoverage": true,
|
||||||
|
9
packages/toast/test/__snapshots__/index.spec.js.snap
Normal file
9
packages/toast/test/__snapshots__/index.spec.js.snap
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`create a forbidClick toast 1`] = `
|
||||||
|
<div class="van-toast van-toast--text van-toast--middle" style="display: none;" name="van-fade">
|
||||||
|
<div></div>
|
||||||
|
<!---->
|
||||||
|
<!---->
|
||||||
|
</div>
|
||||||
|
`;
|
70
packages/toast/test/index.spec.js
Normal file
70
packages/toast/test/index.spec.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import Toast from '../';
|
||||||
|
import Vue from 'vue';
|
||||||
|
import { TransitionStub } from '@vue/test-utils';
|
||||||
|
|
||||||
|
Vue.component('transition', TransitionStub);
|
||||||
|
|
||||||
|
test('create a forbidClick toast', () => {
|
||||||
|
const toast = Toast({
|
||||||
|
forbidClick: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(toast.$el.outerHTML).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('toast disappeared after duration', (done) => {
|
||||||
|
const toast = Toast({
|
||||||
|
duration: 10
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(toast.$el.style.display).toEqual('none');
|
||||||
|
done();
|
||||||
|
}, 500);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clear toast', () => {
|
||||||
|
const toast1 = Toast();
|
||||||
|
expect(toast1.value).toBeTruthy();
|
||||||
|
Toast.clear();
|
||||||
|
expect(toast1.value).toBeFalsy();
|
||||||
|
|
||||||
|
Toast.allowMultiple();
|
||||||
|
const toast2 = Toast('2');
|
||||||
|
const toast3 = Toast('3');
|
||||||
|
Toast.clear(true);
|
||||||
|
expect(toast2.value).toBeFalsy();
|
||||||
|
expect(toast3.value).toBeFalsy();
|
||||||
|
Toast.allowMultiple(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('multiple toast', () => {
|
||||||
|
Toast.allowMultiple();
|
||||||
|
Toast.clear(true);
|
||||||
|
const toast1 = Toast.success('1');
|
||||||
|
const toast2 = Toast.success('2');
|
||||||
|
Toast.clear();
|
||||||
|
expect(toast1.value).toBeFalsy();
|
||||||
|
expect(toast2.value).toBeTruthy();
|
||||||
|
Toast.clear();
|
||||||
|
Toast.clear();
|
||||||
|
expect(toast2.value).toBeFalsy();
|
||||||
|
Toast.allowMultiple(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('set default options', () => {
|
||||||
|
Toast.setDefaultOptions({ duration: 1000 });
|
||||||
|
expect(Toast().duration).toEqual(1000);
|
||||||
|
Toast.resetDefaultOptions();
|
||||||
|
expect(Toast().duration).toEqual(3000);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('toast duration 0', () => {
|
||||||
|
Toast.allowMultiple();
|
||||||
|
const toast = Toast({
|
||||||
|
message: 'toast',
|
||||||
|
duration: 0
|
||||||
|
});
|
||||||
|
expect(toast.timer).toBeFalsy();
|
||||||
|
Toast.allowMultiple(false);
|
||||||
|
});
|
@ -9,7 +9,7 @@
|
|||||||
<template v-if="displayStyle === 'default'">
|
<template v-if="displayStyle === 'default'">
|
||||||
<loading v-if="type === 'loading'" color="white" :type="loadingType" />
|
<loading v-if="type === 'loading'" color="white" :type="loadingType" />
|
||||||
<icon v-else :class="b('icon')" :name="type" />
|
<icon v-else :class="b('icon')" :name="type" />
|
||||||
<div v-if="hasMessage" :class="b('text')">{{ message }}</div>
|
<div v-if="isDef(message)" :class="b('text')">{{ message }}</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
@ -18,6 +18,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import create from '../utils/create';
|
import create from '../utils/create';
|
||||||
import Popup from '../mixins/popup';
|
import Popup from '../mixins/popup';
|
||||||
|
import { isDef } from '../utils';
|
||||||
|
|
||||||
const STYLE_LIST = ['success', 'fail', 'loading'];
|
const STYLE_LIST = ['success', 'fail', 'loading'];
|
||||||
|
|
||||||
@ -49,11 +50,11 @@ export default create({
|
|||||||
computed: {
|
computed: {
|
||||||
displayStyle() {
|
displayStyle() {
|
||||||
return STYLE_LIST.indexOf(this.type) !== -1 ? 'default' : this.type;
|
return STYLE_LIST.indexOf(this.type) !== -1 ? 'default' : this.type;
|
||||||
},
|
|
||||||
|
|
||||||
hasMessage() {
|
|
||||||
return this.message || this.message === 0;
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
isDef
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user