Skip to content

Commit

Permalink
test: mock resize observer and element.animate
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Dec 10, 2024
1 parent 6d22e36 commit 0e492dd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ global.TextEncoder = TextEncoder;
global as { IntersectionObserver: typeof IntersectionObserver }
).IntersectionObserver = IntersectionObserverPassive;

// We mock ResizeObserver and element.animate because neither JSDOM nor Happy DOM supports them, while Svelte v5 requires them.
// Interesting related thread: https://github.com/testing-library/svelte-testing-library/issues/284
global.ResizeObserver = class ResizeObserver {
observe() {
// do nothing
}
unobserve() {
// do nothing
}
disconnect() {
// do nothing
}
};

Element.prototype.animate = vi
.fn()
.mockImplementation(() => ({ cancel: vi.fn(), finished: Promise.resolve() }));

// testing-library setup
configure({
testIdAttribute: "data-tid",
Expand Down

0 comments on commit 0e492dd

Please sign in to comment.