radio.test.js 2.0 KB
Newer Older
Y
yurj26 已提交
1
function getData(key = '') {
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5
  return new Promise(async (resolve, reject) => {
    const data = await page.data()
    resolve(key ? data[key] : data)
  })
Y
yurj26 已提交
6 7 8 9
}

let page
beforeAll(async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
10 11
  page = await program.reLaunch('/pages/component/radio/radio')
  await page.waitFor(1000)
Y
yurj26 已提交
12 13 14
})

describe('Radio.uvue', () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  it('change', async () => {
    const radio = await page.$('.r')
    const radio1 = await page.$('.r1')
    const radio2 = await page.$('.r2')
    expect(await getData('value')).toEqual('')
    await radio1.tap()
    expect(await getData('value')).toEqual('r1')
    await radio.tap()
    expect(await getData('value')).toEqual('r')
    await radio2.tap()
    expect(await getData('value')).toEqual('r')
  })
  it('length', async () => {
    const radioGroupElements = await page.$$('.radio-group')
    expect(radioGroupElements.length).toBe(3)
    const radioElements = await page.$$('.radio')
    expect(radioElements.length).toBe(11)
  })
  it('text', async () => {
    const radio = await page.$('.r1')
    expect(await radio.text()).toEqual('未选中')
    await page.setData({
      text: 'not selected',
    })
    expect(await radio.text()).toEqual('not selected')
  })
  it('checked', async () => {
    const radio = await page.$('.r')
    expect(await radio.property('checked')).toBe(true)
    await page.setData({
      checked: false,
    })
    await page.waitFor(500)
    expect(await radio.property('checked')).toBe(false)
  })
  it('color', async () => {
    const radio = await page.$('.r')
    expect(await radio.property('color')).toBe('#007aff')
    await page.setData({
      color: '#63acfc',
Y
yurj26 已提交
55
    })
DCloud-WZF's avatar
DCloud-WZF 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68
    await page.waitFor(500)
    expect(await radio.property('color')).toBe('#63acfc')
  })
  it('disabled', async () => {
    const radio = await page.$('.r2')
    expect(await radio.property('disabled')).toBe(true)
    await page.setData({
      disabled: false,
    })
    await page.waitFor(500)
    expect(await radio.property('disabled')).toBe(false)
  })
})