-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
TypeError: window.matchMedia is not a function in Vitest #821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
My mistake, it's working fine. All I needed to do was to create a and put this code: Object.defineProperty(window, 'matchMedia', {
writable: 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(),
})),
}) Then, at vite.config.ts I changed the config for test. Like this: test: {
include: ['test/**/*.test.ts'],
environment: 'jsdom',
deps: {
inline: ['@vue', '@vueuse', 'vue-demi', '@vue/composition-api'],
},
setupFiles: [resolve(__dirname, 'test/setup/setup.ts')],
reporters: 'dot',
}, |
chaii3
pushed a commit
to chaii3/vitest
that referenced
this issue
May 13, 2022
* feat(useFuse): new function (#806) Reactive wrapper for Fuse.js. Issues: #806 * feat(useFuse): switch styling to use Windi CSS and adjust styles Issues: #806, vitest-dev#821 * refactor(useFuse): export each export individually Issues: #806, vitest-dev#821 * feat(useFuse): use `tryOnScopeDispose` to cleanup automatically Issues: #806, vitest-dev#821 * feat(useFuse): export return type of `useFuse` Issues: #806, vitest-dev#821 * feat(useFuse): change result type to be `Fuse.FuseResult` Allows the other properties of the Fuse results to be used (i.e `matches` and `score`) and makes it consistent with vanilla Fuse. Issues: #806, vitest-dev#821 * fix(useFuse): fix un-updated property access in the demo The demo was still using `result.index` instead of `result.refIndex`. * feat(useFuse): merge the `fuseOptions` parameter into the `options` parameter Issues: #806, vitest-dev#821 * chore: cleanup * chore: improve dark mode Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
chaii3
pushed a commit
to chaii3/vitest
that referenced
this issue
May 13, 2022
* feat(useFuse): remove unused parameters in arrow function in `shuffleData` in demo * feat(useFuse): make demo mobile-friendly Convert from using `Grid` to using `Flexbox`. Fix some incorrect WindiCSS classes. Issues: vitest-dev#821 * feat(useFuse): add result count display and tweak styling Issues: vitest-dev#857
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
This is my first vue3 testing experience. In this project, I'm using Vitest mount testing and got an error "TypeError: window.matchMedia is not a function."
I read through Vitest documentation and also Jest (Just in case), then I found the "[official workaround]"(https://stackoverflow.com/questions/39830580/jest-test-fails-typeerror-window-matchmedia-is-not-a-function), but it does not work.
full error code:
Reproduction
You can use my repo to test it: https://github.com/matheusgomes062/mgodev
the file path is
/test/component.test.ts
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: