test(expandable-tile): add unit tests

This commit is contained in:
Eric Liu 2025-03-20 15:50:54 -07:00
commit f89e9df8f0
5 changed files with 263 additions and 22 deletions

View file

@ -6,4 +6,41 @@ import "../css/all.css";
// Mock scrollIntoView since it's not implemented in JSDOM
Element.prototype.scrollIntoView = vi.fn();
// Mock ResizeObserver since it's not implemented in JSDOM
class ResizeObserverMock {
callback: ResizeObserverCallback;
elements: Element[];
constructor(callback: ResizeObserverCallback) {
this.callback = callback;
this.elements = [];
}
observe(element: Element) {
this.elements.push(element);
this.callback(
[
{
target: element,
contentRect: { height: 100 } as DOMRectReadOnly,
borderBoxSize: [],
contentBoxSize: [],
devicePixelContentBoxSize: [],
},
],
this,
);
}
unobserve(element: Element) {
this.elements = this.elements.filter((el) => el !== element);
}
disconnect() {
this.elements = [];
}
}
global.ResizeObserver = ResizeObserverMock;
export const user = userEvent.setup();