title: Vue test utils for Vue3 : document is not defined
body: <p>I try to bootstrap a simple app based on the following <code>Vue3</code>, <code>Vite</code>, <code>Vitest</code></p>
  <p>I also installed the vue 3 compatible version of <a href="https://next.vue-test-utils.vuejs.org/guide/" rel="nofollow noreferrer">vue test utils</a> to test vue components.</p>
  <p>I have an error trying to replicate the basic example in the docs :</p>
  <pre><code>import { mount } from &quot;@vue/test-utils&quot;;
  import { expect, test } from 'vitest'
  
  
  // The component to test
  const MessageComponent = {
    template: &quot;&lt;p&gt;{{ msg }}&lt;/p&gt;&quot;,
    props: [&quot;msg&quot;],
  };
  
  test(&quot;displays message&quot;, () =&gt; {
    const wrapper = mount(MessageComponent, {
      props: {
        msg: &quot;Hello world&quot;,
      },
    });
  
    // Assert the rendered text of the component
    expect(wrapper.text()).toContain(&quot;Hello world&quot;);
  });
  
  </code></pre>
  <pre><code> FAIL  src/tests/hello-world.test.ts &gt; displays message
  ReferenceError: document is not defined
   ❯ Proxy.mount node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:7840:14
      7838|     addToDoNotStubComponents(component);
      7839|     registerStub({ source: originalComponent, stub: component });
      7840|     var el = document.createElement('div');
         |              ^
      7841|     if (options === null || options === void 0 ? void 0 : options.attachTo) {
      7842|         var to = void 0;
  Re-running tests... [ src/tests/hello-world.test.ts ]
  
  </code></pre>
  <p>My package.json</p>
  <pre><code>{
    &quot;name&quot;: &quot;vite-vue3-poc&quot;,
    &quot;version&quot;: &quot;0.0.0&quot;,
    &quot;scripts&quot;: {
      &quot;serve&quot;: &quot;vite preview&quot;,
      &quot;build&quot;: &quot;vite build&quot;,
      &quot;coverage&quot;: &quot;vitest --coverage&quot;,
      &quot;dev&quot;: &quot;vite&quot;,
      &quot;preview&quot;: &quot;vite preview&quot;,
      &quot;test&quot;: &quot;vitest&quot;
    },
    &quot;dependencies&quot;: {
      &quot;@mdi/font&quot;: &quot;5.9.55&quot;,
      &quot;prettier&quot;: &quot;^2.5.1&quot;,
      &quot;roboto-fontface&quot;: &quot;*&quot;,
      &quot;vue&quot;: &quot;^3.2.25&quot;,
      &quot;vuetify&quot;: &quot;^3.0.0-alpha.0&quot;,
      &quot;webfontloader&quot;: &quot;^1.0.0&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;@vitejs/plugin-vue&quot;: &quot;^2.0.0&quot;,
      &quot;@vue/cli-plugin-babel&quot;: &quot;5.0.0-beta.7&quot;,
      &quot;@vue/cli-service&quot;: &quot;5.0.0-beta.7&quot;,
      &quot;@vue/test-utils&quot;: &quot;^2.0.0-rc.18&quot;,
      &quot;@vuetify/vite-plugin&quot;: &quot;^1.0.0-alpha.3&quot;,
      &quot;sass&quot;: &quot;^1.38.0&quot;,
      &quot;sass-loader&quot;: &quot;^10.0.0&quot;,
      &quot;vite&quot;: &quot;^2.7.2&quot;,
      &quot;vitest&quot;: &quot;^0.1.23&quot;,
      &quot;vue-cli-plugin-vuetify&quot;: &quot;~2.4.5&quot;,
      &quot;vuetify-loader&quot;: &quot;^2.0.0-alpha.0&quot;
    }
  }
  
  </code></pre>
  <p>vite.config.js</p>
  <pre><code>import { defineConfig } from &quot;vite&quot;;
  import vue from &quot;@vitejs/plugin-vue&quot;;
  import vuetify from &quot;@vuetify/vite-plugin&quot;;
  
  import path from &quot;path&quot;;
  /// &lt;reference types=&quot;vitest&quot; /&gt;
  
  // Configure Vitest (https://vitest.dev/config)
  
  // https://vitejs.dev/config/
  export default defineConfig({
    test: {
      /* for example, use global to avoid globals imports (describe, test, expect): */
      // globals: true,
    },
    plugins: [
      vue(),
  
      // https://github.com/vuetifyjs/vuetify-loader/tree/next/packages/vite-plugin
      vuetify({
        autoImport: true,
      }),
    ],
    define: { &quot;process.env&quot;: {} },
    resolve: {
      alias: {
        &quot;@&quot;: path.resolve(__dirname, &quot;src&quot;),
      },
    },
  });
  
  </code></pre>