From bd7ee34eba9c138ac204b98442428ba74251430c Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 24 Sep 2023 15:25:17 +0800 Subject: [PATCH] test(Dialog): enable function-call test cases (#12315) --- .../__snapshots__/function-call.spec.tsx.snap | 9 +++++++ ...nction-call.jsx => function-call.spec.tsx} | 24 ++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 packages/vant/src/dialog/test/__snapshots__/function-call.spec.tsx.snap rename packages/vant/src/dialog/test/{function-call.jsx => function-call.spec.tsx} (71%) diff --git a/packages/vant/src/dialog/test/__snapshots__/function-call.spec.tsx.snap b/packages/vant/src/dialog/test/__snapshots__/function-call.spec.tsx.snap new file mode 100644 index 000000000..3b1fef710 --- /dev/null +++ b/packages/vant/src/dialog/test/__snapshots__/function-call.spec.tsx.snap @@ -0,0 +1,9 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`should allow to render JSX message 1`] = ` +
+
+ foo +
+
+`; diff --git a/packages/vant/src/dialog/test/function-call.jsx b/packages/vant/src/dialog/test/function-call.spec.tsx similarity index 71% rename from packages/vant/src/dialog/test/function-call.jsx rename to packages/vant/src/dialog/test/function-call.spec.tsx index 4ab02bd27..6a69573a8 100644 --- a/packages/vant/src/dialog/test/function-call.jsx +++ b/packages/vant/src/dialog/test/function-call.spec.tsx @@ -6,20 +6,25 @@ import { resetDialogDefaultOptions, } 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 text = 'hello world'; - setDialogDefaultOptions({ message: 'foo', teleport: wrapper, }); - showDialog(); + setDialogDefaultOptions({ message: text }); + showDialog({ teleport: wrapper }); await later(); const dialog = wrapper.querySelector('.van-dialog'); - expect(dialog.innerHTML.includes('foo')).toBeTruthy(); + + assert(dialog); + expect(dialog.innerHTML.includes(text)).toBeTruthy(); resetDialogDefaultOptions(); showDialog({ teleport: wrapper }); await later(); 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 () => { @@ -42,13 +47,14 @@ test('should close dialog after calling closeDialog', async () => { }); await later(); - const dialog = wrapper.querySelector('.van-dialog'); + const dialog = wrapper.querySelector('.van-dialog') as HTMLElement; + expect(dialog.style.display).toEqual(''); closeDialog(); await later(); 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(); - const dialog = wrapper.querySelector('.van-dialog'); + const dialog = wrapper.querySelector('.van-dialog') as HTMLElement; expect( - dialog.querySelector('.van-dialog__message').outerHTML + dialog.querySelector('.van-dialog__message')?.outerHTML, ).toMatchSnapshot(); });