0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/webapi/test/offscreencanvas.js
2022-03-07 21:37:50 +00:00

57 lines
1.1 KiB
JavaScript

import { assert, test } from '../run/test.setup.js'
import { polyfill } from '../mod.js'
test(() => {
return [
{
name: 'Supports OffscreenCanvas',
test() {
const target = {}
polyfill(target)
assert.equal('OffscreenCanvas' in target, true)
assert.equal(typeof target['OffscreenCanvas'], 'function')
},
},
{
name: 'Supports new (width: number, height: number): OffscreenCanvas',
test() {
const target = {}
polyfill(target)
const w = 640
const h = 480
const canvas = new target.OffscreenCanvas(w, h)
assert.equal(canvas.width, w)
assert.equal(canvas.height, h)
},
},
{
name: 'Supports OffscreenCanvas#getContext',
test() {
const target = {}
polyfill(target)
const w = 640
const h = 480
const canvas = new target.OffscreenCanvas(w, h)
const context = canvas.getContext('2d')
assert.equal(context.canvas, canvas)
const imageData = context.createImageData(w, h)
assert.equal(imageData.width, w)
assert.equal(imageData.height, h)
assert.equal(imageData.data.length, w * h * 4)
},
},
]
})