2022-04-11 01:29:46 +00:00
|
|
|
import { expect } from 'chai'
|
2022-03-07 21:36:22 +00:00
|
|
|
import { polyfill } from '../mod.js'
|
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
describe('ImageData', () => {
|
|
|
|
const target = {}
|
2022-03-07 21:37:50 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
before(() => polyfill(target))
|
2022-03-07 21:37:50 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
it('Supports ImageData', () => {
|
|
|
|
expect(target).to.have.property('ImageData').that.is.a('function')
|
|
|
|
})
|
2022-03-07 21:37:50 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
it('Supports new (data: Uint8ClampedArray, width: number, height: number): ImageData', () => {
|
|
|
|
const w = 640
|
|
|
|
const h = 480
|
|
|
|
const d = new Uint8ClampedArray(w * h * 4)
|
2022-03-07 21:36:22 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
const id = new target.ImageData(d, w, h)
|
2022-03-07 21:36:22 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
expect(id.data).to.equal(d)
|
|
|
|
expect(id.width).to.equal(w)
|
|
|
|
expect(id.height).to.equal(h)
|
|
|
|
})
|
2022-03-07 21:36:22 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
it('Supports new (data: Uint8ClampedArray, width: number): ImageData', () => {
|
|
|
|
const w = 640
|
|
|
|
const h = 480
|
|
|
|
const d = new Uint8ClampedArray(w * h * 4)
|
2022-03-07 21:37:50 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
const id = new target.ImageData(d, w)
|
2022-03-07 21:36:22 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
expect(id.data).to.equal(d)
|
|
|
|
expect(id.width).to.equal(w)
|
|
|
|
expect(id.height).to.equal(h)
|
|
|
|
})
|
2022-03-07 21:36:22 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
it('Supports new (width: number, height: number): ImageData', () => {
|
|
|
|
const w = 640
|
|
|
|
const h = 480
|
2022-03-07 21:36:22 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
const id = new target.ImageData(w, h)
|
2022-03-07 21:37:50 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
expect(id.data).to.have.lengthOf(w * h * 4)
|
|
|
|
expect(id.width).to.equal(w)
|
|
|
|
expect(id.height).to.equal(h)
|
|
|
|
})
|
2022-03-07 21:36:22 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
it('Supports Object.keys(new ImageData(640, 480))', () => {
|
|
|
|
const keys = Object.keys(new target.ImageData(640, 480))
|
2022-03-07 21:36:22 +00:00
|
|
|
|
2022-04-11 01:29:46 +00:00
|
|
|
expect(keys).to.have.lengthOf(1)
|
|
|
|
expect(keys[0]).to.equal('data')
|
|
|
|
})
|
2022-03-07 21:36:22 +00:00
|
|
|
})
|