Installation of Vue Test Utils
As of now, Vitest provides us, out of the box, with tools to test plain JavaScript functions, classes, events, and so on. To test our Single File Components, we need additional resources, and these are provided to us again by the official Vue team in the form of Vue Test Utils (https://test-utils.vuejs.org/). To install them, run the following command:
$ npm install -D @vue/test-utils
Once the installation has completed, we need to update our vite.config.js
file to include the environment where the components will be tested, meaning a browser context. Modify the configuration file so it looks like this:
export default defineConfig({ plugins: [vue()], test:{environment:"jsdom"} })
Vitest and Vue Test Utils both integrate seamlessly with Vite, to the point that they share the same configuration file. You can now run the test suite, and Vitest will attempt to download and install any missing...