Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxtlink-failing #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions components/NavBar.nuxt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import type { VueWrapper } from '@vue/test-utils'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { describe, expect, it } from 'vitest'

import NavBar from './NavBar.vue'

describe('navBar', () => {
// Helper functions to get elements by data-testid
const findHomeLink = (wrapper: VueWrapper) => wrapper.find('[data-testid="home-link"]')
const findMoviesLink = (wrapper: VueWrapper) => wrapper.find('[data-testid="movies-link"]')
const findTVShowsLink = (wrapper: VueWrapper) => wrapper.find('[data-testid="tv-shows-link"]')
const findSearchLink = (wrapper: VueWrapper) => wrapper.find('[data-testid="search-link"]')

it('renders Home link correctly', async () => {
const wrapper = await mountSuspended(NavBar)

// test true to be true
expect(true).toBe(true)

// const homeLink = findHomeLink(wrapper)
// expect(homeLink.exists()).toBe(true)
// expect(homeLink.attributes('title')).toBe('Home')
})

// it('renders Movies link correctly', async () => {
// const wrapper = await mountSuspended(NavBar)
// const moviesLink = findMoviesLink(wrapper)
// expect(moviesLink.exists()).toBe(true)
// expect(moviesLink.attributes('title')).toBe('Movies')
// })

// it('renders TV Shows link correctly', async () => {
// const wrapper = await mountSuspended(NavBar)
// const tvShowsLink = findTVShowsLink(wrapper)
// expect(tvShowsLink.exists()).toBe(true)
// expect(tvShowsLink.attributes('title')).toBe('TV Shows')
// })

// it('renders Search link correctly', async () => {
// const wrapper = await mountSuspended(NavBar)
// const searchLink = findSearchLink(wrapper)
// expect(searchLink.exists()).toBe(true)
// expect(searchLink.attributes('title')).toBe('Search')
// })

// it('applies active class to the correct link', async () => {
// const wrapper = await mountSuspended(NavBar)

// const homeLink = findHomeLink(wrapper)
// const moviesLink = findMoviesLink(wrapper)
// const tvShowsLink = findTVShowsLink(wrapper)
// const searchLink = findSearchLink(wrapper)

// // Simulate navigation to the home page
// await wrapper.vm.$router.push('/')
// await wrapper.vm.$nextTick()
// expect(homeLink.find('div').classes()).toContain('i-ph-house-fill')
// expect(moviesLink.find('div').classes()).not.toContain('i-ph-film-strip-fill')
// expect(tvShowsLink.find('div').classes()).not.toContain('i-ph-television-simple-fill')
// expect(searchLink.find('div').classes()).not.toContain('i-ph-magnifying-glass-fill')

// // Simulate navigation to the movies page
// await wrapper.vm.$router.push('/movie')
// await wrapper.vm.$nextTick()
// expect(homeLink.find('div').classes()).not.toContain('i-ph-house-fill')
// expect(moviesLink.find('div').classes()).toContain('i-ph-film-strip-fill')
// expect(tvShowsLink.find('div').classes()).not.toContain('i-ph-television-simple-fill')
// expect(searchLink.find('div').classes()).not.toContain('i-ph-magnifying-glass-fill')

// // Simulate navigation to the TV shows page
// await wrapper.vm.$router.push('/tv')
// await wrapper.vm.$nextTick()
// expect(homeLink.find('div').classes()).not.toContain('i-ph-house-fill')
// expect(moviesLink.find('div').classes()).not.toContain('i-ph-film-strip-fill')
// expect(tvShowsLink.find('div').classes()).toContain('i-ph-television-simple-fill')
// expect(searchLink.find('div').classes()).not.toContain('i-ph-magnifying-glass-fill')

// // Simulate navigation to the search page
// await wrapper.vm.$router.push('/search')
// await wrapper.vm.$nextTick()
// expect(homeLink.find('div').classes()).not.toContain('i-ph-house-fill')
// expect(moviesLink.find('div').classes()).not.toContain('i-ph-film-strip-fill')
// expect(tvShowsLink.find('div').classes()).not.toContain('i-ph-television-simple-fill')
// expect(searchLink.find('div').classes()).toContain('i-ph-magnifying-glass-fill')
// })
})
8 changes: 4 additions & 4 deletions components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
border="t lg:r base"
bg-black
>
<NuxtLink v-slot="{ isActive }" to="/" :title="$t('Home')">
<NuxtLink v-slot="{ isActive }" to="/" :title="$t('Home')" data-testid="home-link">
<div
text-2xl

Check failure on line 11 in components/NavBar.vue

View workflow job for this annotation

GitHub Actions / build (20.x)

Unhandled error

TypeError: Cannot destructure property 'isActive' of 'undefined' as it is undefined. ❯ components/NavBar.vue:11:17 ❯ renderFnWithContext node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:689:13 ❯ normalizeChildren node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7599:34 ❯ createBaseVNode node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7404:5 ❯ _createVNode node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7481:10 ❯ createVNodeWithArgsTransform node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7358:10 ❯ Module.h node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:8118:12 ❯ Proxy.<anonymous> node_modules/@nuxt/test-utils/dist/runtime-utils/index.mjs:64:108 ❯ renderComponentRoot node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6445:16 ❯ ReactiveEffect.componentUpdateFn [as fn] node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5262:46 This error originated in "components/NavBar.nuxt.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "renders Home link correctly". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.
:class="isActive ? 'i-ph-house-fill text-primary' : 'i-ph-house'"
/>
</NuxtLink>
<NuxtLink v-slot="{ isActive }" to="/movie" :title="$t('Movies')">
<NuxtLink v-slot="{ isActive }" to="/movie" :title="$t('Movies')" data-testid="movies-link">
<div
text-2xl
:class="isActive ? 'i-ph-film-strip-fill text-primary' : 'i-ph-film-strip'"
/>
</NuxtLink>
<NuxtLink v-slot="{ isActive }" to="/tv" :title="$t('TV Shows')">
<NuxtLink v-slot="{ isActive }" to="/tv" :title="$t('TV Shows')" data-testid="tv-shows-link">
<div
text-2xl
:class="isActive ? 'i-ph-television-simple-fill text-primary' : 'i-ph-television-simple'"
/>
</NuxtLink>
<NuxtLink v-slot="{ isActive }" to="/search" :title="$t('Search')">
<NuxtLink v-slot="{ isActive }" to="/search" :title="$t('Search')" data-testid="search-link">
<div
text-2xl
:class="isActive ? 'i-ph-magnifying-glass-fill text-primary' : 'i-ph-magnifying-glass'"
Expand Down
Loading