canvas.test.js 2.0 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
})

describe('Canvas.uvue', () => {
  it('toBlob', async () => {
13 14 15
    if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('web')) {
      const testToBlobResult = await page.data('testToBlobResult')
      const testToDataURLResult = await page.data('testToDataURLResult')
16 17 18

      expect(testToBlobResult).toBe(true)
      expect(testToDataURLResult).toBe(true)
19 20 21
    } else {
      // app skip
      expect(true).toBe(true)
22 23
    }
  })
24
  it("测试异步创建canvas上下文", async () => {
25 26 27
    // await page.callMethod('useAsync');
    await page.waitFor(500)
    const element = await page.$('#testCanvasContext')
28
    expect(await element.text()).toBe('true')
29
  })
30 31 32 33 34
  // it("测试同步创建canvas上下文", async () => {
  //   await page.callMethod('useAsync');
  //   const element = await page.$('#testCanvasContext')
  //   expect(await element.text()).toBe('true')
  // })
35
  it('测试 canvasToDataURL', async () => {
36
    await page.callMethod('canvasToDataURL');
37 38
    const element = await page.$('#testToDataURLResult')
    expect(await element.text()).toBe('true')
39
  })
40
  // 配合安卓注释
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  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')
  })
59
})