canvas.test.js 1.2 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  it("测试异步方式", async () => {
    await page.callMethod('useAsync');
    const {
      testCanvasContext,
      testToDataURLResult
    } = await page.data()
    expect(testCanvasContext).toBe(true)
    await page.callMethod('canvasToDataURL');
    expect(testToDataURLResult).toBe(true)
  })
  it("测试同步方式", async () => {
    await page.callMethod('useSync');
    const data = await page.data()
    expect(data.testCanvasContext).toBe(true)
    await page.callMethod('canvasToDataURL');
    expect(data.testToDataURLResult).toBe(true)
  })
43
})