39 questions
22
votes
7
answers
27k
views
How to mock/stub vue-i18n?
I have started to replace Jest with Vitest for my unit test library in my Vue 3 App.
I am trying to write unit test for a component that uses the vue-i18n library to translate text within it but when ...
3
votes
1
answer
272
views
Invalid PostCSS Plugin found using TailwindCSS 4 and Vitest
I have a Next.js app that is running without any errors. However, I am using Vitest for my testing framework and when running a specific test (layout.test.tsx) it produces this error:
FAIL src/app/...
15
votes
1
answer
35k
views
vitest global variables in setupfiles
How do I get variables defined in my setup files to work in my test files?
Setup files:
var lol = 'lol'
test:
describe("test", () => {
it("test lol", () => {
expect(...
9
votes
3
answers
19k
views
Mocking axios.create using vitest
I am using axios.create method to create and configure axios instance. And I can't get it to work in tests with vi.fn() so I cannot assert if endpoint was called.
workaround for tests to be able to ...
6
votes
1
answer
14k
views
Vue3- Using Vitest toHaveBeenCalled() method
I am running a vue3 application using the Composition API and the setup() hook.
I am using Vitest as unit-test framework. (v 0.6.1)
I have the following sample component :
// src/components/...
0
votes
0
answers
247
views
An error occurs when writing tests for node:crypto with Vitest
I want to write tests for the following function using Vitest.
import { randomUUID } from "node:crypto";
export const getRandomUUID = (): string => {
return randomUUID();
}
I wrote ...
26
votes
4
answers
33k
views
"describe is not defined" in Vitest
I'm starting out with Vite for a React application but unable to get jest tests working. I am trying to use Vitest with experimental ES module.
I am getting:
FAIL src/App.test.tsx [ src/App.test.tsx ]...
11
votes
0
answers
3k
views
Vitest error SyntaxError: At least one <template> or <script> is required in a single file component
I am using Vitest for Vue Unit Testing and I am currently faced with this error:
FAIL tests/unit/components/MyComponent.spec.js [ tests/unit/components/MyComponent.spec.js ]
SyntaxError: At least one ...
8
votes
1
answer
28k
views
Vitest error "TypeError: Cannot read properties of undefined (reading 'resolve')" (router.resolve)
I have a very basic test, however it throws the error below when I try to mount a component const wrapper = mount(HomeHeader). I've pasted my vite config, test, component and packages.
This error ...
7
votes
1
answer
7k
views
Vitest coverage on azure devops
I'm trying to run an azure devops pipeline that contains a vitest run with coverage. The issue is that the azure coverage collector plugin accepts only jacoco/cobertura formats.
I've seen that for ...
6
votes
1
answer
3k
views
Tailwind CSS classes not applied as styles during Vitest testing
I am currently using Vite with Vitest to perform unit testing for my React components. However, I am encountering an issue where the Tailwind CSS classes applied to my components are not being ...
6
votes
5
answers
6k
views
Unable to test vue component with v-dialog
I have been killing myself trying to figure out how to test a Vue component with a v-dialog, something which worked perfectly fine in Vue2. Currently I am using Vue3, Vitest, Vuetify3.
here is a very ...
4
votes
1
answer
2k
views
Vitest: Wrapper doesn't show "teleported" HTML
imagine we have two components, Modal.vue which is lets say a component that is used to display modal content (uses slots to take in JSX), and Component.vue which is the one with content we wish to ...
4
votes
2
answers
8k
views
TypeError with Vitest: Cannot read properties of null (reading 'useRef')
I am trying to set up testing for my React app using Vitest, but I am experiencing an error which must be due to some missing dependency or error in my test suite. I'm unsure what exactly is the cause....
3
votes
1
answer
5k
views
(MSW + React-Query + Vitest) Requests occurring in prior test fail in subsequent test
I have built a ReactJS application using Vite, and I am testing my application using Vitest.
I make heavy usage of react-query within my application. For mocking network requests during testing, I ...
2
votes
0
answers
2k
views
Show Vitest coverage on Azure DevOps UI
I would render my vitest coverage in Azure DevOps UI, I've tried to follow tutorials but it doesn't work:
I tried to setup PublishCodeCoverageResults to publish the cobertura xml file as in below:
...
1
vote
1
answer
5k
views
Disable auto reload vite reactjs
My application requires a very extensive loading for certain functions, but vite updates the page by itself causing the loading to restart and lose all the progress already made on the page, I would ...
0
votes
1
answer
363
views
Type error in TypeScript 5.6: Type '() => Generator<string, void, any>' is not assignable to type '() => BuiltinIterator<string, undefined, any>'
For my unit tests I create a fake window.location object. Here's the slightly simplified code:
function getFakeLocation(getCurrentUrl: () => URL): Location {
return {
get ancestorOrigins(): ...
0
votes
1
answer
7k
views
How to check if component function have been called using Vue3, Vitest, and Vue Test Utils?
I have a component written in Vue 3 and script setup. Now I am trying to write a unit test for it, where I am instantiating a spy to check whether a function has been called.
I read somewhere that ...
-2
votes
1
answer
858
views
How to set global window for jQuery in a vitest test (jQuery requires a window with a document)?
Probably less important: Setup is done with webpack Encore which generates a webpack config file, we use yarn as a package manager, so vitest is installed with yarn.
jQuery version 3.6.4
vitest ...