From f1719674682a90fab7da03aa142d43a7966d4d4b Mon Sep 17 00:00:00 2001 From: hdx Date: Wed, 29 May 2024 15:10:14 +0800 Subject: [PATCH] =?UTF-8?q?test(form):=20=E5=A2=9E=E5=8A=A0=20event=20/=20?= =?UTF-8?q?target=20/=20tagName=20=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/form/form.test.js | 10 ++++++++-- pages/component/form/form.uvue | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pages/component/form/form.test.js b/pages/component/form/form.test.js index ed51aa55..faa9024b 100644 --- a/pages/component/form/form.test.js +++ b/pages/component/form/form.test.js @@ -28,7 +28,8 @@ describe('form', () => { await page.waitFor(200) const { - formData + formData, + testVerifySubmit } = await page.data() expect(formData['nickname']).toBe(CHANGE_NICK_NAME) @@ -38,6 +39,8 @@ describe('form', () => { expect(formData['age']).toBe(CHANGE_AGE) expect(formData['switch']).toBe(CHANGE_SWITCH) expect(formData['comment']).toBe(CHANGE_COMMENT) + + expect(testVerifySubmit).toBe(true) }) it('reset', async () => { await changeData(page) @@ -51,7 +54,8 @@ describe('form', () => { await page.waitFor(100) const { - formData + formData, + testVerifyReset } = await page.data() expect(formData['nickname']).toBe(DEFAULT_NICK_NAME) @@ -60,6 +64,8 @@ describe('form', () => { expect(formData['age']).toBe(DEFAULT_AGE) expect(formData['switch']).toBe(DEFAULT_SWITCH) expect(formData['comment']).toBe(DEFAULT_COMMENT) + + expect(testVerifyReset).toBe(true) }) }) diff --git a/pages/component/form/form.uvue b/pages/component/form/form.uvue index 49f53e65..664b38d3 100644 --- a/pages/component/form/form.uvue +++ b/pages/component/form/form.uvue @@ -68,7 +68,10 @@ loves: ['0'], switch: true, comment:'', - formData: {} as UTSJSONObject + formData: {} as UTSJSONObject, + // 仅测试 + testVerifySubmit: false, + testVerifyReset: false, } }, computed: { @@ -78,10 +81,18 @@ }, methods: { onFormSubmit: function (e : UniFormSubmitEvent) { + console.log(e.target?.tagName ?? '123'); + console.log(e.type); this.formData = e.detail.value + + // 仅测试 + this.testVerifySubmit = (e.type == 'submit' && (e.target?.tagName ?? '') == "FORM") }, - onFormReset: function (_ : UniFormResetEvent) { + onFormReset: function (e : UniFormResetEvent) { this.formData = {} + + // 仅测试 + this.testVerifyReset = (e.type == 'reset' && (e.target?.tagName ?? '') == "FORM") } } } -- GitLab