提交 9047d30c 编写于 作者: H hdx

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

上级 0d22164a
...@@ -6,22 +6,6 @@ describe('switch', () => { ...@@ -6,22 +6,6 @@ describe('switch', () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500) await page.waitFor(500)
}) })
// TODO
// it('click', async () => {
// const switch_element = await page.$('.switch-checked')
// const switch_element_value = await page.$('.switch-checked-value')
// expect(await switch_element_value.text()).toBe('true')
// await page.waitFor(200)
// await switch_element.tap()
// await page.waitFor(200)
// expect(await switch_element_value.text()).toBe('false')
// await switch_element.tap()
// await page.waitFor(200)
// expect(await switch_element_value.text()).toBe('true')
// })
it('checked', async () => { it('checked', async () => {
const switch_element = await page.$('.switch-checked') const switch_element = await page.$('.switch-checked')
...@@ -53,4 +37,16 @@ describe('switch', () => { ...@@ -53,4 +37,16 @@ describe('switch', () => {
await page.waitFor(100) await page.waitFor(100)
expect(await switch_element.attribute('color')).toBe(color) expect(await switch_element.attribute('color')).toBe(color)
}) })
it('click', async () => {
// TODO 暂时通过获取组件内部的 class 触发模拟点击
const switchElement = await page.$('.uni-switch-input')
await switchElement.tap()
await page.waitFor(200)
const {
testVerifyEvent
} = await page.data()
expect(testVerifyEvent).toBe(true)
})
}) })
...@@ -39,13 +39,17 @@ ...@@ -39,13 +39,17 @@
title: 'switch 开关', title: 'switch 开关',
checked: true, checked: true,
color: '#FFCC33', color: '#FFCC33',
clickCheckedValue: true clickCheckedValue: true,
testVerifyEvent: false,
} }
}, },
methods: { methods: {
switch1Change: function (e : UniSwitchChangeEvent) { switch1Change: function (e : UniSwitchChangeEvent) {
this.clickCheckedValue = e.detail.value this.clickCheckedValue = e.detail.value
console.log('switch1 发生 change 事件,携带值为', e.detail.value) console.log('switch1 发生 change 事件,携带值为', e.detail.value)
// 仅测试
this.testVerifyEvent = (e.type == 'change' && (e.target?.tagName ?? '') == "SWITCH")
}, },
switch2Change: function (e : UniSwitchChangeEvent) { switch2Change: function (e : UniSwitchChangeEvent) {
console.log('switch2 发生 change 事件,携带值为', e.detail.value) console.log('switch2 发生 change 事件,携带值为', e.detail.value)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册