提交 f1719674 编写于 作者: H hdx 提交者: 雪洛

test(form): 增加 event / target / tagName 验证

上级 508ad032
...@@ -28,7 +28,8 @@ describe('form', () => { ...@@ -28,7 +28,8 @@ describe('form', () => {
await page.waitFor(200) await page.waitFor(200)
const { const {
formData formData,
testVerifySubmit
} = await page.data() } = await page.data()
expect(formData['nickname']).toBe(CHANGE_NICK_NAME) expect(formData['nickname']).toBe(CHANGE_NICK_NAME)
...@@ -38,6 +39,8 @@ describe('form', () => { ...@@ -38,6 +39,8 @@ describe('form', () => {
expect(formData['age']).toBe(CHANGE_AGE) expect(formData['age']).toBe(CHANGE_AGE)
expect(formData['switch']).toBe(CHANGE_SWITCH) expect(formData['switch']).toBe(CHANGE_SWITCH)
expect(formData['comment']).toBe(CHANGE_COMMENT) expect(formData['comment']).toBe(CHANGE_COMMENT)
expect(testVerifySubmit).toBe(true)
}) })
it('reset', async () => { it('reset', async () => {
await changeData(page) await changeData(page)
...@@ -51,7 +54,8 @@ describe('form', () => { ...@@ -51,7 +54,8 @@ describe('form', () => {
await page.waitFor(100) await page.waitFor(100)
const { const {
formData formData,
testVerifyReset
} = await page.data() } = await page.data()
expect(formData['nickname']).toBe(DEFAULT_NICK_NAME) expect(formData['nickname']).toBe(DEFAULT_NICK_NAME)
...@@ -60,6 +64,8 @@ describe('form', () => { ...@@ -60,6 +64,8 @@ describe('form', () => {
expect(formData['age']).toBe(DEFAULT_AGE) expect(formData['age']).toBe(DEFAULT_AGE)
expect(formData['switch']).toBe(DEFAULT_SWITCH) expect(formData['switch']).toBe(DEFAULT_SWITCH)
expect(formData['comment']).toBe(DEFAULT_COMMENT) expect(formData['comment']).toBe(DEFAULT_COMMENT)
expect(testVerifyReset).toBe(true)
}) })
}) })
......
...@@ -68,7 +68,10 @@ ...@@ -68,7 +68,10 @@
loves: ['0'], loves: ['0'],
switch: true, switch: true,
comment:'', comment:'',
formData: {} as UTSJSONObject formData: {} as UTSJSONObject,
// 仅测试
testVerifySubmit: false,
testVerifyReset: false,
} }
}, },
computed: { computed: {
...@@ -78,10 +81,18 @@ ...@@ -78,10 +81,18 @@
}, },
methods: { methods: {
onFormSubmit: function (e : UniFormSubmitEvent) { onFormSubmit: function (e : UniFormSubmitEvent) {
console.log(e.target?.tagName ?? '123');
console.log(e.type);
this.formData = e.detail.value this.formData = e.detail.value
// 仅测试
this.testVerifySubmit = (e.type == 'submit' && (e.target?.tagName ?? '') == "FORM")
}, },
onFormReset: function (_ : UniFormResetEvent) { onFormReset: function (e : UniFormResetEvent) {
this.formData = {} this.formData = {}
// 仅测试
this.testVerifyReset = (e.type == 'reset' && (e.target?.tagName ?? '') == "FORM")
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册