mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
test(expandable-tile): add unit tests
This commit is contained in:
parent
ed8e2dc75b
commit
3ccd0ea56d
5 changed files with 263 additions and 22 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue