You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had problems with the module from the very beginning. Unfortunately, there is almost no information in the documentation on how to configure the module. I've searched all over the internet and still can't run the tests. Here are the things I did in a nutshell:
I installed a previous version of Vitest to make it compatible with the nuxt-vitest module
I defined the environment as jsdom
I configured the setup file to have access to window.matchMedia
I have specified that coverage should not take virtual nuxt into account
The testing module is still not working. What else should I do? Unfortunately, Stackblitz does not allow reproduction. Here is my configuration:
import{Blob}from'node:buffer';import{afterEach,beforeAll,vi}from'vitest';console.log('--- setup ---');Object.defineProperty(window,'matchMedia',{writable: true,value: vi.fn().mockImplementation((query)=>({matches: false,media: query,onchange: null,addListener: vi.fn(),// deprecatedremoveListener: vi.fn(),// deprecatedaddEventListener: vi.fn(),removeEventListener: vi.fn(),dispatchEvent: vi.fn(),})),});beforeAll(()=>{// @ts-expect-errorglobalThis.Blob=Blob;console.log('📝 Before all Setup...');});afterEach(()=>{vi.clearAllMocks();});// // TypeError: window.matchMedia is not a function// // https://github.com/vitest-dev/vitest/issues/821#issuecomment-1046954558// console.log('---setup');
~/tests/components/F24Teest.nuxt.spec.ts
import{mountSuspended}from'nuxt-vitest/utils';importTeestfrom'~/components/Teest.vue';it('can also mount an app',async()=>{constcomponent=awaitmountSuspended(Teest,{route: '/-tests'});expect(component.text()).toMatchInlineSnapshot('"..."');});
Finally, after many hours, I managed to make a workaround for these errors. The problem was mainly in the nuxt virtual files and the @vite-pwa/nuxt module.
Workaround for "TypeError: window.matchMedia is not a function" error
In nuxt.config.ts:
I had problems with the module from the very beginning. Unfortunately, there is almost no information in the documentation on how to configure the module. I've searched all over the internet and still can't run the tests. Here are the things I did in a nutshell:
nuxt-vitest
moduleThe testing module is still not working. What else should I do? Unfortunately, Stackblitz does not allow reproduction. Here is my configuration:
~/vitest.config.mjs
~/tests/setup.ts
~/tests/components/F24Teest.nuxt.spec.ts
~/components/Teest.vue
~/pages/-test/index.vue
Nuxi info:
My output:
I cleared the cache, reinstalled all modules and I still really have no idea what to do. I would be grateful for help 🙏.
The text was updated successfully, but these errors were encountered: