All Questions
39 questions
0
votes
0
answers
35
views
Vitest Stuck when running in a Docker Container
I would like to run the Vitest Unit tests of my Nuxt application on Github Actions in a Docker container, but the tests do not start, but get stuck on the output to be seen below. I'm currently ...
0
votes
0
answers
26
views
How to mock multiple refs (and refs in general) in Nuxt?
I'm looking for a way to mock multiple refs (and refs in general) in Nuxt? I'm using Vitest and Nuxt test utils.
About my Case:
I want to test a SideBar.vue component. The component has multiple refs:
...
0
votes
0
answers
69
views
Nuxt registerendpoint also mocks child paths
I am just starting to write unit tests inside my nuxt project. now i have the problem that i have an endpoint path available which also has subpaths, like this:
endpoint 1: /animal/dog
endpoint 2: /...
1
vote
0
answers
136
views
Failed to resolve import "#app/composables/script-stubs (Vitest)
I am receiving the error 'Failed to resolve import "#app/composables/script-stubs"' inside the .nuxt folder in the imports.d.ts file
My code is like this and I've tried importing everything.....
0
votes
1
answer
218
views
Configuration Vitest in Nuxt 3
I have a large project made with Nuxt 3, Vue, Pinia, Axios, and TypeScript.
I need help with configuring Vitest to work in my project.
I've had many problems. For example, I wrote a test and it didn't ...
0
votes
3
answers
362
views
Mocking useStorage() using @nuxt/test-utils
The goal is to write a test for a function that uses KV storage, under the hood provided by Nitro, in the Nuxt app. On the client side useStorage() is automatically imported. When writing a test, ...
0
votes
0
answers
115
views
Nuxt testing: detect child component events
I am trying to test a nuxt page with vitest.
It has a child component toolbar which emits an event "on-click". When this event is triggered, the page calls a method "onClick". My ...
1
vote
1
answer
508
views
Unit test error using 'Vitest, @nuxt/test-utils' (SyntaxError: At least one <template> or <script> is required for each file component. )
Objective:
I want to test an API via useFetch from Vuetify components.
Error occurrence:
To achieve this goal, I've used '@nuxt/test-utils/runtime'.
However, I encountered errors in the logs.
To ...
1
vote
1
answer
321
views
How to mock Supabase in Vitest?
I've got a Nuxt3 application that uses the @nuxtjs/supabase module for auth and storage, and am trying to add Vitest unit testing to it.
In my app.vue, I have the following:
<script lang="ts&...
2
votes
1
answer
739
views
Warning about wrong type
I'm trying to use Vitest in a Nuxt3 + Vuetify3 project. I'm trying to start really simple, which is why my only test so far is mounting a component. The test passes, however, it's always throwing a ...
0
votes
0
answers
232
views
Nuxt Vitest page unit testing with SSR: false
I am trying to performed End to End testing on my index.vue page according to the documentation. My project requires that SSR is false but, when disabled, my Vitest unit tests fail.
This is my index....
0
votes
0
answers
82
views
ReferenceError for mocked modules in Vitest
I am just getting started with Vitest in a Nuxt app with Nitro and stuggling to getting the mocking right it seems as I keep getting ReferenceErrors.
My spec aims at testing a module in the /server ...
0
votes
0
answers
300
views
Vitest testing components of a Nuxt.Js project (using primevue component library)
I am making a web application using Nuxt.js. I am fairly new to this framework. The component I have finished working on is a wizard component. This wizard is a modal that takes in an array of form ...
-1
votes
1
answer
3k
views
Uncaught (in promise) TypeError: Cannot read properties of null (reading 'parentNode') - router.push({})
I have recently upgraded my dependencies and now every time I click on my button to navigate to the next page (and thus triggers router.push({ path: getBaseRoute("next-route") }) it throws ...
7
votes
3
answers
679
views
How to check if navigateTo was called in nuxt.js
I'm working on a Nuxt.js project and using Vitest for unit testing. I need to verify if the navigateTo function from Nuxt.js is called with a specific path in my tests.
Here's the relevant part of my ...
0
votes
0
answers
863
views
Trouble with Nuxt Content Module, Vitest, nuxt unit test and Test Setup
I'm encountering issues while trying to set up unit tests for my Nuxt application using the Nuxt Content module and Vitest. Here's a breakdown of my situation:
I have a Nuxt application using the Nuxt ...
1
vote
0
answers
771
views
Error: Nuxt instance is unavailable! In Vitest with Nuxt environment
I'm busy implementing unit tests for our Nuxt application. Testing components that don't use any Nuxt modules run fine without any issues but testing a component with an installed Nuxt module throws ...
0
votes
1
answer
667
views
Vitest - How do I assert that a flat function was called within a composable?
I'm working with Vitest and Nuxt 3. I am trying to assert that useHead() was called with a given argument from inside a custom-written composable. In Vitest, you can create a spy to assert that a ...
2
votes
0
answers
1k
views
Can't mock Vue composable function with vitest
In a Vue/Nuxt project, to separate the all the business logic and data, I have created a new function with the help of Vue composition api.
The custom composable function will help me to do some ...
0
votes
0
answers
78
views
ReferenceError: toRefs is not defined
I am trying to use vitest with nuxt 3. Since,nuxt has auto-import feature I am not importing it but when I am writing unit test in vitest its giving me error ReferenceError: toRefs is not defined how ...
0
votes
1
answer
4k
views
ReferenceError: definePageMeta is not defined
Description:
In my vue 3 and nuxt 3 project, i'm using vitest for test. But i've a problem when i run test:
ReferenceError: definePageMeta is not defined
- /pages/client/login.vue:869:5
- /...
1
vote
1
answer
1k
views
How to test that a vue component has rendered after a pinia state change?
I'm trying to write a unit test which checks whether a component has rendered when the pinia state has changed.
I would expect that store.menuIsActive = true would mean that expect(toolbar.exists())....
1
vote
0
answers
2k
views
How to setup unit tests for Nuxt3?
I created a new Nuxt3 app via npx nuxi init <project-name> and want to add unit tests. Based on the docs for testing I called npm install -D @nuxt/test-utils vitest and started with ./pages/foo....
0
votes
2
answers
2k
views
Vitest and nuxt 3 form submit testing
I got a form in a nuxt 3 app with three input fields. Here is how the submit function looks like:
const submitForm = async () => {
try {
await $fetch("/api/contact", {
...
3
votes
0
answers
901
views
Vue-Test-Utils (Vitest) doesn't recognize Nuxt useRouter as a function
I am using Nuxt 3 on the current project at work. We just started writing tests (this is my first time doing that). I'm trying to test a component which has Nuxt useRouter and my basic test fails ...
2
votes
0
answers
2k
views
Testing in nuxt 3 (vitest/jest)
I have a nuxt 3.2.3 app and i want to test it. Nuxt is supporting both Jest and Vitest for testing, but i read somewhere that Vitest is the recommended one.
On the other hand @nuxt/test-utils package ...
9
votes
3
answers
5k
views
Vitest setup auto-import for Nuxt and pinia
I'm trying to setup vitest + @vue/test-utils but I can't test some components that use ref(Vue) or useCookie (Nuxt), I have the same problem with Pinia as well where I import globally 2 functions in ...
7
votes
1
answer
2k
views
nuxt3: how to test SSR page with form, useFetch() and pinia?
In my Nuxt3 project, I have a very basic login page which is SSR like the following:
pages/login.vue
<template>
<form
@submit.prevent="login">
<input
...
0
votes
1
answer
2k
views
ERROR [worker reload] [worker init] Cannot read properties of undefined (reading 'config')
I installed Nuxt3 with vuetify and Vitest:
1.install nuxt3
npx nuxi init [name-ap] //install nuxt3 app
cd name-app
npm i
npm i vuetify@next sass
3. Create plugin for vuetify
create new folder: '...
0
votes
3
answers
1k
views
How to test a function that uses Nitro's useStorage
I have created a function that allows to manage caching.
I use this function to cache the responses to API calls.
export const cache = async (key: string, callback: Function) => {
const ...
16
votes
2
answers
41k
views
Vitest mock modules function in only one test and use the actual function in others
The following is an abstraction of my problem and thus does not make too much sense:
Given I have a simple utility callMethodIf that's returning the return of another imported method (blackbox).
~~/...
9
votes
2
answers
8k
views
Test a component with Vitest using useNuxtApp with Nuxt 3
I want to test a component using the useNuxtApp composable.
This is the component(MyComponent.vue):
<template>
<div class="flex justify-between">
<span>{{ $fmt(12) }}&...
5
votes
1
answer
3k
views
ReferenceError: computed is not defined on Vitest test suite
Description
I'm migrating test suites from Jest to Vitest.
But i've a problem when i run test suites, an error occurs when a component has a computed property.
The common error is :
ReferenceError: ...
3
votes
1
answer
5k
views
Nuxt Vitest Mock useRoute in another module
I am trying to write a test for the following Nuxt 3 composable (useLinkToSlug).
import { computed } from 'vue';
export default function () {
const route = useRoute();
return computed(() =>...
1
vote
0
answers
2k
views
Aliases not resolved in vitest
I want to use aliases in tests files with vitest:
import { describe, expect, it } from 'vitest'
import Plan from '@/modules/Pricing/models/Plan'
let plan: Plan
describe('Plan model', () => {
it(...
6
votes
1
answer
2k
views
How would definePageMeta will be Mocked in Vitest?
I was trying Vitest to write UTs for my app which has Nuxt on the top of Vue.
But I am getting definePageMeta as undefined when trying to mock test.vue.
Here is my component test.vue -
<script ...
8
votes
1
answer
10k
views
How to write unit test for components with vitest in Nuxt 3?
I'm trying to migrate from Vue 3 to Nuxt 3. I've written unit tests for my components using vitest which are working fine in my Vue app, but the same test in the Nuxt app give me the following error:
...
2
votes
2
answers
4k
views
How to use paths in vitest with Nuxt3?
I have nuxt3_rc_3 project and using vitest to test the utilities I wrote for project
utils/index.ts imports few constants from ~~/config/constants
While writing test in test/utils/index.test.ts I ...
7
votes
4
answers
7k
views
Testing Pinia store inside Nuxt3 with vitest throws `useRuntimeConfig` not defined
I am testing pinia store in nuxt3 app.
Inside setup() of store I'm using useRuntimeConfig to get initial value for counter from public config variables and I got this error ReferenceError: ...