[Improvement] Toast: add test cases (#1104)

This commit is contained in:
neverland
2018-05-19 09:57:45 +08:00
committed by GitHub
parent bb74fd0bd5
commit 3d669b4a81
4 changed files with 86 additions and 5 deletions
@@ -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
View 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);
});