canvas.test.js 1.9 KB
Newer Older
1 2
let page

3 4 5 6
beforeAll(async () => {
  // if (!process.env.uniTestPlatformInfo.toLowerCase().startsWith('web')) {
  //   return
  // }
7
  page = await program.reLaunch('/pages/component/canvas/canvas')
8
  await page.waitFor(500)
9 10 11 12 13 14 15 16 17 18 19 20
})

describe('Canvas.uvue', () => {
  it('toBlob', async () => {
    if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('web')) {
      const {
        testToBlobResult,
        testToDataURLResult
      } = await page.data()

      expect(testToBlobResult).toBe(true)
      expect(testToDataURLResult).toBe(true)
21 22 23
    } else {
      // app skip
      expect(true).toBe(true)
24 25
    }
  })
26
  it("测试异步创建canvas上下文", async () => {
27 28 29
    // await page.callMethod('useAsync');
    await page.waitFor(500)
    const element = await page.$('#testCanvasContext')
30
    expect(await element.text()).toBe('true')
31
  })
32 33 34 35 36
  // it("测试同步创建canvas上下文", async () => {
  //   await page.callMethod('useAsync');
  //   const element = await page.$('#testCanvasContext')
  //   expect(await element.text()).toBe('true')
  // })
37
  it('测试 canvasToDataURL', async () => {
38
    await page.callMethod('canvasToDataURL');
39 40
    const element = await page.$('#testToDataURLResult')
    expect(await element.text()).toBe('true')
41
  })
42
  // 配合安卓注释
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
  it('测试 createImage', async () => {
    if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('web')) {
      // web skip
      expect(true).toBe(true)
    } else {
      await page.callMethod('onCreateImage');
      await page.waitFor(500) // 加载图片
      const element = await page.$('#testCreateImage')
      expect(await element.text()).toBe('true')
    }
  })
  it('测试 testCreatePath2D', async () => {
    // onCreatePath2D
    await page.callMethod('onCreatePath2D');
    await page.waitFor(50)
    const element = await page.$('#testCreatePath2D')
    expect(await element.text()).toBe('true')
  })
61
})