canvas.test.js 1.5 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
    await page.callMethod('useAsync');
28
    // const element = await page.$('#testCanvasContext')
29
    expect(await element.text()).toBe('true')
30
  })
31 32 33 34 35
  // it("测试同步创建canvas上下文", async () => {
  //   await page.callMethod('useAsync');
  //   const element = await page.$('#testCanvasContext')
  //   expect(await element.text()).toBe('true')
  // })
36
  it('测试 canvasToDataURL', async () => {
37
    await page.callMethod('canvasToDataURL');
38 39
    const element = await page.$('#testToDataURLResult')
    expect(await element.text()).toBe('true')
40
  })
41
  it('测试 createImage', async () => {
42
    await page.callMethod('onCreateImage');
43 44 45 46
    await page.waitFor(500) // 加载图片
    const element = await page.$('#testCreateImage')
    expect(await element.text()).toBe('true')
  })
47
})