Skip to content

Commit 96e7135

Browse files
committed
mock pointer events for tests
1 parent f6b6053 commit 96e7135

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/setupTests.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,25 @@ window.matchMedia = window.matchMedia || function() {
1010
addListener: function() {},
1111
removeListener: function() {}
1212
};
13-
};
13+
};
14+
15+
// Mock PointerEvent methods for JSDOM
16+
if (typeof window !== 'undefined' && typeof window.HTMLElement !== 'undefined') {
17+
window.HTMLElement.prototype.setPointerCapture = window.HTMLElement.prototype.setPointerCapture || function(pointerId) {};
18+
window.HTMLElement.prototype.releasePointerCapture = window.HTMLElement.prototype.releasePointerCapture || function(pointerId) {};
19+
// Mock hasPointerCapture to return true after setPointerCapture is called, needed for our component logic
20+
const originalSetPointerCapture = window.HTMLElement.prototype.setPointerCapture;
21+
const capturedPointers = new Set();
22+
window.HTMLElement.prototype.setPointerCapture = function(pointerId) {
23+
capturedPointers.add(pointerId);
24+
originalSetPointerCapture.call(this, pointerId);
25+
};
26+
const originalReleasePointerCapture = window.HTMLElement.prototype.releasePointerCapture;
27+
window.HTMLElement.prototype.releasePointerCapture = function(pointerId) {
28+
capturedPointers.delete(pointerId);
29+
originalReleasePointerCapture.call(this, pointerId);
30+
};
31+
window.HTMLElement.prototype.hasPointerCapture = window.HTMLElement.prototype.hasPointerCapture || function(pointerId) {
32+
return capturedPointers.has(pointerId);
33+
};
34+
}

0 commit comments

Comments
 (0)