test(Dialog): enable function-call test cases (#12315)

This commit is contained in:
neverland 2023-09-24 15:25:17 +08:00 committed by GitHub
parent 0477c0e2e6
commit bd7ee34eba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 9 deletions

View File

@ -0,0 +1,9 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`should allow to render JSX message 1`] = `
<div class="van-dialog__message">
<div>
foo
</div>
</div>
`;

View File

@ -6,20 +6,25 @@ import {
resetDialogDefaultOptions, resetDialogDefaultOptions,
} from '../function-call'; } from '../function-call';
test('should update default options when calling setDefaultOptions method', () => { test('should update default options when calling setDefaultOptions method', async () => {
const wrapper = document.createElement('div'); const wrapper = document.createElement('div');
const text = 'hello world';
setDialogDefaultOptions({ message: 'foo', teleport: wrapper, }); setDialogDefaultOptions({ message: text });
showDialog(); showDialog({ teleport: wrapper });
await later(); await later();
const dialog = wrapper.querySelector('.van-dialog'); const dialog = wrapper.querySelector('.van-dialog');
expect(dialog.innerHTML.includes('foo')).toBeTruthy();
assert(dialog);
expect(dialog.innerHTML.includes(text)).toBeTruthy();
resetDialogDefaultOptions(); resetDialogDefaultOptions();
showDialog({ teleport: wrapper }); showDialog({ teleport: wrapper });
await later(); await later();
const dialog2 = wrapper.querySelector('.van-dialog'); const dialog2 = wrapper.querySelector('.van-dialog');
expect(dialog2.innerHTML.includes('foo')).toBeFalsy();
assert(dialog2);
expect(dialog2.innerHTML.includes(text)).toBeFalsy();
}); });
test('should render dialog after calling showDialog', async () => { test('should render dialog after calling showDialog', async () => {
@ -42,13 +47,14 @@ test('should close dialog after calling closeDialog', async () => {
}); });
await later(); await later();
const dialog = wrapper.querySelector('.van-dialog'); const dialog = wrapper.querySelector('.van-dialog') as HTMLElement;
expect(dialog.style.display).toEqual(''); expect(dialog.style.display).toEqual('');
closeDialog(); closeDialog();
await later(); await later();
expect(dialog.className.split(' ')).toContain( expect(dialog.className.split(' ')).toContain(
'van-dialog-bounce-leave-active' 'van-dialog-bounce-leave-active',
); );
}); });
@ -60,8 +66,8 @@ test('should allow to render JSX message', async () => {
}); });
await later(); await later();
const dialog = wrapper.querySelector('.van-dialog'); const dialog = wrapper.querySelector('.van-dialog') as HTMLElement;
expect( expect(
dialog.querySelector('.van-dialog__message').outerHTML dialog.querySelector('.van-dialog__message')?.outerHTML,
).toMatchSnapshot(); ).toMatchSnapshot();
}); });