Yuri
Yuri
NNuxt
Created by murchikov on 1/8/2025 in #❓・help
skill issue
Hello. This port may be is busied by another process. Try to change it to another.
export default defineNuxtConfig({
devServer: {
port: 3001
}
})
export default defineNuxtConfig({
devServer: {
port: 3001
}
})
12 replies
NNuxt
Created by Yuri on 1/4/2025 in #❓・help
postcss-normalize
@kapa.ai but styles don't reset.
9 replies
NNuxt
Created by NepaliJesus on 12/25/2024 in #❓・help
How to not have nested layout/pages refresh when the main layout changes
Can you give a real example why you need this case?
15 replies
NNuxt
Created by NepaliJesus on 12/25/2024 in #❓・help
How to not have nested layout/pages refresh when the main layout changes
But why are you worrying about refresh? In the real world the user's screen doesn't change during browsing.
15 replies
NNuxt
Created by NepaliJesus on 12/25/2024 in #❓・help
How to not have nested layout/pages refresh when the main layout changes
Why do you need change the layout? When the page loads you know the user device. For my project I create the global middleware:
export default defineNuxtRouteMiddleware((to, _from) => {
const { isMobile } = useDevice()

if (isMobile) {
to.meta.layout = 'mobile'
}
else {
to.meta.layout = 'default'
}
})
export default defineNuxtRouteMiddleware((to, _from) => {
const { isMobile } = useDevice()

if (isMobile) {
to.meta.layout = 'mobile'
}
else {
to.meta.layout = 'default'
}
})
It helps me.
15 replies
NNuxt
Created by Yuri on 12/26/2024 in #❓・help
Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.
Yes, I know about 3.15. Thank you )
11 replies
NNuxt
Created by Yuri on 12/26/2024 in #❓・help
Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.
@kapa.ai warning => warning.message.includes('The legacy JS API is deprecated') It doesn't work. Do you have another idea?
11 replies
NNuxt
Created by Yuri on 12/25/2024 in #❓・help
Testing $fetch
@kapa.ai Error: Test timed out in 5000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
20 replies
NNuxt
Created by Yuri on 12/25/2024 in #❓・help
Testing $fetch
@kapa.ai now I get a new error:
Error: Cannot find import "$fetch" to mock
Plugin: nuxt:vitest:mock-transform
Error: Cannot find import "$fetch" to mock
Plugin: nuxt:vitest:mock-transform
20 replies
NNuxt
Created by Yuri on 12/25/2024 in #❓・help
Testing $fetch
@kapa.ai I get a new error:
TypeError: $fetch.mockResolvedValue is not a function
TypeError: $fetch.mockResolvedValue is not a function
20 replies
NNuxt
Created by Yuri on 12/15/2024 in #❓・help
"async-component-wrapper-stub" testing
Ups... It was the mistake in the name of the imported component. This is correct: SearchQuickSuggestsComponent = wrapper.findComponent(SearchQuickSuggests); Test is pass.
6 replies
NNuxt
Created by Yuri on 12/14/2024 in #❓・help
The test ignores useNuxtApp
I decided to change mountSuspended to mount. It helped me.
13 replies
NNuxt
Created by Yuri on 12/14/2024 in #❓・help
The test ignores useNuxtApp
@kapa.ai import {describe, it, expect, vi} from 'vitest' import {mockNuxtImport, mountSuspended} from '@nuxt/test-utils/runtime' import LocationSelection from '../LocationSelection.vue' import {flushPromises} from "@vue/test-utils"; describe('LocationSelection.vue', () => { it('test', async () => { // Mock the $api method to return a resolved promise const mockApi = vi.fn().mockResolvedValue({ data: 'mocked data' }) const wrapper = await mountSuspended(LocationSelection, { globals: { provide: { nuxtApp: { $api: mockApi } } } }) await wrapper.vm.$nextTick() await flushPromises() console.log(wrapper.html()) expect(wrapper.text()).toContain('333') }) }) Not working import { describe, it, expect } from 'vitest' import {mockNuxtImport, mountSuspended} from '@nuxt/test-utils/runtime' import LocationSelection from '../LocationSelection.vue' describe('LocationSelection.vue', () => { mockNuxtImport('useNuxtApp', () => { return () => ({ $api: () => Promise.resolve() // Mock the $api method }) }) it('test', async () => { const wrapper = await mountSuspended(LocationSelection) await wrapper.vm.$nextTick() console.log(wrapper.html()) expect(wrapper.text()).toContain('333') }) }) Not working
13 replies
NNuxt
Created by Yuri on 12/13/2024 in #❓・help
useNuxtApp && mountSuspended
@kapa.ai with first solution I get errors: [Vue warn]: Component is missing template or render function: { name: 'MountSuspendedHelper', setup: [AsyncFunction: setup] } at <MountSuspendedHelper> at <Anonymous ref="VTU_COMPONENT" > at <VTUROOT> ❯ components/Location/tests/LocationSelection.nuxt.spec.ts (1) ❯ LocationSelection.vue (1) × test ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ FAIL components/Location/tests/LocationSelection.nuxt.spec.ts > LocationSelection.vue > test TypeError: nuxtApp.deferHydration is not a function ❯ Object.setup node_modules/nuxt/dist/app/components/nuxt-root.vue:32:27 30| 31| const IslandRenderer = import.meta.server && componentIslands 32| ? defineAsyncComponent(() => import('./island-renderer').then(r => r.default || r)) | ^ 33| : () => null 34| ❯ setup node_modules/@nuxt/test-utils/dist/runtime-utils/index.mjs:107:50 ❯ callWithErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19 ❯ setupStatefulComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7788:25 ❯ setupComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7749:36 ❯ mountComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5104:7 ❯ processComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5070:9 ❯ patch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:4599:11 ❯ ReactiveEffect.componentUpdateFn [as fn] node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5214:11 ❯ ReactiveEffect.run node_modules/@vue/runtime-core/node_modules/@vue/reactivity/dist/reactivity.cjs.js:226:19
10 replies
NNuxt
Created by Yuri on 12/13/2024 in #❓・help
Unit Test OnMounted
@kapa.ai My component:
import { debounce, upperCase } from 'lodash'
import type { ILocationCitySuggestItem, ILocationCitySuggests } from '~/types/location'
import { useLocationStore } from '~/store/location'

const locationStore = useLocationStore()
const customCSS = useCustomCSS()

const searchText = ref('')
const cities: Ref<ILocationCitySuggestItem[]> = ref([])
const initialCities: Ref<ILocationCitySuggestItem[]> = ref([]) //
const isLoading = ref(false)

const fetchCities = async (query: string | null = null) => {
isLoading.value = true
const nuxtApp = useNuxtApp()
const params = query ? { query: upperCase(query) } : {}
const response = await nuxtApp.$api<ILocationCitySuggests>(apiPath.location.suggest.city, { params })
cities.value = response.items
isLoading.value = false
}

const debouncedFetchCities = debounce(() => fetchCities(searchText.value), 300)

watch(searchText, (newVal) => {
if (newVal) {
debouncedFetchCities()
}
else {
cities.value = initialCities.value
}
})
onMounted(async () => {
await fetchCities()
initialCities.value = cities.value
})

const selectLocation = async (id: number) => {
await locationStore.updateCurrent(id)
}
import { debounce, upperCase } from 'lodash'
import type { ILocationCitySuggestItem, ILocationCitySuggests } from '~/types/location'
import { useLocationStore } from '~/store/location'

const locationStore = useLocationStore()
const customCSS = useCustomCSS()

const searchText = ref('')
const cities: Ref<ILocationCitySuggestItem[]> = ref([])
const initialCities: Ref<ILocationCitySuggestItem[]> = ref([]) //
const isLoading = ref(false)

const fetchCities = async (query: string | null = null) => {
isLoading.value = true
const nuxtApp = useNuxtApp()
const params = query ? { query: upperCase(query) } : {}
const response = await nuxtApp.$api<ILocationCitySuggests>(apiPath.location.suggest.city, { params })
cities.value = response.items
isLoading.value = false
}

const debouncedFetchCities = debounce(() => fetchCities(searchText.value), 300)

watch(searchText, (newVal) => {
if (newVal) {
debouncedFetchCities()
}
else {
cities.value = initialCities.value
}
})
onMounted(async () => {
await fetchCities()
initialCities.value = cities.value
})

const selectLocation = async (id: number) => {
await locationStore.updateCurrent(id)
}
And my test:
import LocationSelection from '../LocationSelection.vue'
import {flushPromises} from "@vue/test-utils";

const mockApiResponse = {
items: [
{ id: 1, name: 'City1' }
]
}

const mockApi = vi.fn().mockResolvedValue(mockApiResponse)
mockNuxtImport('useNuxtApp', () => () => ({
$api: mockApi
}))

describe('LocationSelection.vue', () => {
const createWrapper = async () => {
return await mountSuspended(LocationSelection)
}

it('test',async ()=>{
const wrapper = await createWrapper();
await flushPromises();
await wrapper.vm.$nextTick();
console.log(wrapper.html());
})
})
import LocationSelection from '../LocationSelection.vue'
import {flushPromises} from "@vue/test-utils";

const mockApiResponse = {
items: [
{ id: 1, name: 'City1' }
]
}

const mockApi = vi.fn().mockResolvedValue(mockApiResponse)
mockNuxtImport('useNuxtApp', () => () => ({
$api: mockApi
}))

describe('LocationSelection.vue', () => {
const createWrapper = async () => {
return await mountSuspended(LocationSelection)
}

it('test',async ()=>{
const wrapper = await createWrapper();
await flushPromises();
await wrapper.vm.$nextTick();
console.log(wrapper.html());
})
})
But i receive errors: TypeError: nuxtApp.deferHydration is not a function Where is a mistake?
29 replies
NNuxt
Created by Yuri on 12/13/2024 in #❓・help
Unit Test OnMounted
@kapa.ai
29 replies
NNuxt
Created by Yuri on 12/13/2024 in #❓・help
Unit Test OnMounted
1
29 replies
NNuxt
Created by Yuri on 12/13/2024 in #❓・help
Unit Test OnMounted
@kapa.ai My current test:
import { describe, it, vi } from 'vitest'
import { mockNuxtImport, mountSuspended } from '@nuxt/test-utils/runtime'
import LocationSelection from '../LocationSelection.vue'
import {flushPromises} from "@vue/test-utils";

// Mock the API response
const mockApiResponse = {
items: [
{ id: 1, name: 'City1' },
{ id: 2, name: 'City2' }
]
}

const mockApi = vi.fn().mockResolvedValue(mockApiResponse)
mockNuxtImport('useNuxtApp', () => () => ({
$api: mockApi
}))

describe('LocationSelection.vue', () => {
const createWrapper = async () => {
return await mountSuspended(LocationSelection)
}

it('test',async ()=>{
const wrapper = await createWrapper();
await flushPromises();
await wrapper.vm.$nextTick();
console.log(wrapper.html());
})
})
import { describe, it, vi } from 'vitest'
import { mockNuxtImport, mountSuspended } from '@nuxt/test-utils/runtime'
import LocationSelection from '../LocationSelection.vue'
import {flushPromises} from "@vue/test-utils";

// Mock the API response
const mockApiResponse = {
items: [
{ id: 1, name: 'City1' },
{ id: 2, name: 'City2' }
]
}

const mockApi = vi.fn().mockResolvedValue(mockApiResponse)
mockNuxtImport('useNuxtApp', () => () => ({
$api: mockApi
}))

describe('LocationSelection.vue', () => {
const createWrapper = async () => {
return await mountSuspended(LocationSelection)
}

it('test',async ()=>{
const wrapper = await createWrapper();
await flushPromises();
await wrapper.vm.$nextTick();
console.log(wrapper.html());
})
})
But I receive error: TypeError: nuxtApp.deferHydration is not a function ❯ Object.setup node_modules/nuxt/dist/app/components/nuxt-root.vue:32:27 30| 31| const IslandRenderer = import.meta.server && componentIslands 32| ? defineAsyncComponent(() => import('./island-renderer').then(r => r.default || r)) | ^ 33| : () => null 34| ❯ setup node_modules/@nuxt/test-utils/dist/runtime-utils/index.mjs:107:50 ❯ callWithErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19 ❯ setupStatefulComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7788:25 ❯ setupComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7749:36 Vitest caught 1 unhandled error during the test run. This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
29 replies
NNuxt
Created by Yuri on 12/13/2024 in #❓・help
Unit Test OnMounted
@kapa.ai what is correct variant for mock const response = await nuxtApp.$api<ILocationCitySuggests>(apiPath.location.suggest.city, { params })
29 replies