Skip to content

Commit dd1b2a2

Browse files
authored
Merge pull request #7980 from pearmini/fix-mediaElement-copy
Fix MediaElement.copy
2 parents ca9d475 + 50a4d64 commit dd1b2a2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/dom/p5.MediaElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ class MediaElement extends Element {
816816
}
817817
copy(...args) {
818818
this._ensureCanvas();
819-
fn.copy.apply(this, args);
819+
p5.prototype.copy.apply(this, args);
820820
}
821821
mask(...args) {
822822
this.loadPixels();

test/unit/dom/p5.MediaElement.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { vi } from 'vitest';
22
import { mockP5, mockP5Prototype } from '../../js/mocks';
33
import { default as media, MediaElement } from '../../../src/dom/p5.MediaElement';
44
import { Element } from '../../../src/dom/p5.Element';
5+
import { default as pixels } from '../../../src/image/pixels';
56

67
suite('p5.MediaElement', () => {
78
beforeAll(() => {
89
media(mockP5, mockP5Prototype);
10+
pixels(mockP5, mockP5Prototype);
911
navigator.mediaDevices.getUserMedia = vi.fn()
1012
.mockResolvedValue("stream-value");
1113
});
@@ -235,4 +237,22 @@ suite('p5.MediaElement', () => {
235237
assert.isTrue(testElement.elt.playsInline);
236238
});
237239
});
240+
241+
suite("p5.MediaElement.copy", function () {
242+
beforeAll(() => {
243+
globalThis.p5 = { prototype: mockP5Prototype };
244+
});
245+
246+
afterAll(() => {
247+
delete globalThis.p5;
248+
document.body.innerHTML = "";
249+
});
250+
251+
test('should not throw an error', function() {
252+
const testElement = mockP5Prototype.createVideo('/test/unit/assets/nyan_cat.gif');
253+
assert.doesNotThrow(() => {
254+
testElement.copy(0, 0, 10, 10, 0, 0, 10, 10);
255+
});
256+
});
257+
})
238258
});

0 commit comments

Comments
 (0)