Skip to content

Commit

Permalink
add new code
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel3108 committed Dec 23, 2024
1 parent fb5f98a commit 5622141
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/addons/vitest-addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,26 @@ export default defineAddon({
if (content) return content;

return dedent`
import '@testing-library/jest-dom/vitest'
import '@testing-library/jest-dom/vitest';
import {vi} from 'vitest';
// add global mocks here, i.e. for sveltekit '$app/stores'
// needed for svelte/motion that exports new MediaQuery which calls window.matchMedia eagerly
Object.defineProperty(window, "matchMedia", {
writable: true,
enumerable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
`;
});

Expand Down

0 comments on commit 5622141

Please sign in to comment.