Skip to content

Commit 665ec27

Browse files
committed
Test: Add unit test for noSmooth() canvas position in WEBGL
1 parent f59801d commit 665ec27

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/webgl/p5.RendererGL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ class RendererGL extends Renderer {
945945
pg.canvas = document.createElement("canvas");
946946
const node = pg._pInst._userNode || document.body;
947947
node.appendChild(pg.canvas);
948-
p5.Element.call(pg, pg.canvas, pg._pInst);
948+
Element.call(pg, pg.canvas, pg._pInst);
949949
pg.width = w;
950950
pg.height = h;
951951
} else {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { describe, it, expect } from 'vitest';
2+
3+
// Importing p5
4+
import '../../../lib/p5.js';
5+
6+
describe('noSmooth() should preserve canvas position in WEBGL', () => {
7+
it('should maintain the canvas position after calling noSmooth()', () => {
8+
9+
let myP5 = new window.p5((p) => {
10+
p.setup = function () {
11+
let cnv = p.createCanvas(300, 300, p.WEBGL);
12+
cnv.position(150, 50);
13+
14+
const originalTop = cnv.elt.style.top;
15+
const originalLeft = cnv.elt.style.left;
16+
17+
// Call noSmooth()
18+
p.noSmooth();
19+
20+
// Checking if position remains or not
21+
expect(cnv.elt.style.top).toBe(originalTop);
22+
expect(cnv.elt.style.left).toBe(originalLeft);
23+
};
24+
});
25+
});
26+
});

0 commit comments

Comments
 (0)