test(Dialog): update test cases

This commit is contained in:
chenjiahan
2021-01-02 21:42:26 +08:00
parent 101b416fa2
commit 711ffd9d30
5 changed files with 218 additions and 199 deletions
+51
View File
@@ -0,0 +1,51 @@
import { createApp } from 'vue';
import { later } from '../../../test';
import Dialog from '..';
import DialogComponent from '../Dialog';
test('should update default options when calling setDefaultOptions method', () => {
Dialog.setDefaultOptions({ lockScroll: false });
expect(Dialog.currentOptions.lockScroll).toBeFalsy();
Dialog.resetDefaultOptions();
expect(Dialog.currentOptions.lockScroll).toBeTruthy();
});
test('should expose Dialog component', () => {
expect(Dialog.Component).toEqual(DialogComponent);
});
test('should register component to app', () => {
const app = createApp();
app.use(Dialog);
expect(app.component(DialogComponent.name)).toBeTruthy();
});
test('should render dialog after calling Dialog', async () => {
const wrapper = document.createElement('div');
Dialog.alert({
message: '1',
teleport: wrapper,
});
await later();
const dialog = wrapper.querySelector('.van-dialog');
expect(dialog).toBeTruthy();
});
test('should close dialog after calling Dialog.call', async () => {
const wrapper = document.createElement('div');
Dialog.alert({
message: '1',
teleport: wrapper,
});
await later();
const dialog = wrapper.querySelector('.van-dialog');
expect(dialog.style.display).toEqual('');
Dialog.close();
await later();
expect(dialog.className.split(' ')).toContain(
'van-dialog-bounce-leave-active'
);
});