astro/packages/webapi/test/offscreencanvas.js

40 lines
923 B
JavaScript
Raw Normal View History

import { expect } from 'chai'
import { polyfill } from '../mod.js'
describe('OffscreenCanvas', () => {
const target = {}
2022-03-07 21:37:50 +00:00
before(() => polyfill(target))
2022-03-07 21:37:50 +00:00
it('Supports OffscreenCanvas', () => {
expect(target).to.have.property('OffscreenCanvas').that.is.a('function')
})
2022-03-07 21:37:50 +00:00
it('Supports new (width: number, height: number): OffscreenCanvas', () => {
const w = 640
const h = 480
const canvas = new target.OffscreenCanvas(w, h)
expect(canvas.width).to.equal(w)
expect(canvas.height).to.equal(h)
})
it('Supports OffscreenCanvas#getContext', () => {
const w = 640
const h = 480
2022-03-07 21:37:50 +00:00
const canvas = new target.OffscreenCanvas(w, h)
const context = canvas.getContext('2d')
expect(context.canvas).to.equal(canvas)
const imageData = context.createImageData(w, h)
expect(imageData.width).to.equal(w)
expect(imageData.height).to.equal(h)
expect(imageData.data).to.have.lengthOf(w * h * 4)
})
})