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 29 30 31 32
    const element = await page.$('#testCanvasContext')
    expect(await element.text()).toBe('true')

  })
  it("测试同步创建canvas上下文", async () => {
33 34 35
    await page.callMethod('useAsync');
    const element = await page.$('#testCanvasContext')
    expect(await element.text()).toBe('true')
36
  })
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
  it('测试 createImage', async () => {
    await page.callMethod('drawImageAPI');
    await page.waitFor(500) // 加载图片
    const element = await page.$('#testCreateImage')
    expect(await element.text()).toBe('true')
  })
48
})