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

test: fix test failures due to $route not being stringified #3095

Merged
merged 2 commits into from
Sep 12, 2024
Merged
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
16 changes: 7 additions & 9 deletions specs/basic_usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ describe('basic usage', async () => {
expect(await getText(page, '#locale-path')).toEqual('/nl/nuxt-context-extension')

const localeRoute = JSON.parse(await getText(page, '#locale-route')) as RouteLocation
// remove absolute file path which differs where test is run
// remove properties that vary based on test environment and vue-router version
// we only need to know if the correct route (object) is returned
localeRoute.matched = localeRoute.matched.map(x => {
for (const component in x.components) {
// @ts-ignore
delete x.components[component].__file
x.components[component] = {}
}
// @ts-ignore
delete x.mods
return x
})
expect(localeRoute).toMatchInlineSnapshot(
Expand All @@ -117,18 +119,14 @@ describe('basic usage', async () => {
},
"enterCallbacks": {},
"instances": {},
"leaveGuards": {
"Set(0)": [],
},
"leaveGuards": {},
"meta": {},
"name": "nuxt-context-extension___en",
"path": "/nuxt-context-extension",
"props": {
"default": false,
},
"updateGuards": {
"Set(0)": [],
},
"updateGuards": {},
},
],
"meta": {},
Expand Down
4 changes: 3 additions & 1 deletion specs/fixtures/basic_usage/pages/nuxt-context-extension.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script setup></script>

<template>
<div>
<p id="get-route-base-name">{{ $nuxt.$getRouteBaseName($route) }}</p>
<p id="switch-locale-path">{{ $nuxt.$switchLocalePath('ja') }}</p>
<p id="locale-path">{{ $nuxt.$localePath('nuxt-context-extension', 'nl') }}</p>
<p id="locale-route">{{ $nuxt.$localeRoute($route) }}</p>
<p id="locale-route">{{ JSON.stringify($nuxt.$localeRoute()) }}</p>
<p id="locale-head">{{ $nuxt.$localeHead({}) }}</p>
</div>
</template>
44 changes: 22 additions & 22 deletions specs/fixtures/routing/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,32 @@ const localeRoute = useLocaleRoute()
</section>
<ClientOnly>
<section id="locale-route">
<span class="index">{{ localeRoute('/') }}</span>
<span class="index-name-ja">{{ localeRoute('index', 'ja') }}</span>
<span class="about-name">{{ localeRoute('about') }}</span>
<span class="about-ja">{{ localeRoute('/about', 'ja') }}</span>
<span class="about-name-ja">{{ localeRoute('about', 'ja') }}</span>
<span class="about-object-ja">{{ localeRoute({ name: 'about' }, 'ja') }}</span>
<span class="path-match-ja">{{ localeRoute('/:pathMatch(.*)*', 'ja') }}</span>
<span class="path-match-name">{{ localeRoute('pathMatch') }}</span>
<span class="path-match-name-ja">{{ localeRoute('pathMatch', 'ja') }}</span>
<span class="undefined-path-ja">{{ localeRoute('/vue-i18n', 'ja') }}</span>
<span class="undefined-name-ja">{{ localeRoute('vue-i18n', 'ja') }}</span>
<span class="index">{{ JSON.stringify(localeRoute('/')) }}</span>
<span class="index-name-ja">{{ JSON.stringify(localeRoute('index', 'ja')) }}</span>
<span class="about-name">{{ JSON.stringify(localeRoute('about')) }}</span>
<span class="about-ja">{{ JSON.stringify(localeRoute('/about', 'ja')) }}</span>
<span class="about-name-ja">{{ JSON.stringify(localeRoute('about', 'ja')) }}</span>
<span class="about-object-ja">{{ JSON.stringify(localeRoute({ name: 'about' }, 'ja')) }}</span>
<span class="path-match-ja">{{ JSON.stringify(localeRoute('/:pathMatch(.*)*', 'ja')) }}</span>
<span class="path-match-name">{{ JSON.stringify(localeRoute('pathMatch')) }}</span>
<span class="path-match-name-ja">{{ JSON.stringify(localeRoute('pathMatch', 'ja')) }}</span>
<span class="undefined-path-ja">{{ JSON.stringify(localeRoute('/vue-i18n', 'ja')) }}</span>
<span class="undefined-name-ja">{{ JSON.stringify(localeRoute('vue-i18n', 'ja')) }}</span>
</section>
</ClientOnly>
<ClientOnly>
<section id="locale-location">
<span class="index">{{ localeLocation('/') }}</span>
<span class="index-name-ja">{{ localeLocation('index', 'ja') }}</span>
<span class="about-name">{{ localeLocation('about') }}</span>
<span class="about-ja">{{ localeLocation('/about', 'ja') }}</span>
<span class="about-name-ja">{{ localeLocation('about', 'ja') }}</span>
<span class="about-object-ja">{{ localeLocation({ name: 'about' }, 'ja') }}</span>
<span class="path-match-ja">{{ localeLocation('/:pathMatch(.*)*', 'ja') }}</span>
<span class="path-match-name">{{ localeLocation('pathMatch') }}</span>
<span class="path-match-name-ja">{{ localeLocation('pathMatch', 'ja') }}</span>
<span class="undefined-path-ja">{{ localeRoute('/vue-i18n', 'ja') }}</span>
<span class="undefined-name-ja">{{ localeRoute('vue-i18n', 'ja') }}</span>
<span class="index">{{ JSON.stringify(localeLocation('/')) }}</span>
<span class="index-name-ja">{{ JSON.stringify(localeLocation('index', 'ja')) }}</span>
<span class="about-name">{{ JSON.stringify(localeLocation('about')) }}</span>
<span class="about-ja">{{ JSON.stringify(localeLocation('/about', 'ja')) }}</span>
<span class="about-name-ja">{{ JSON.stringify(localeLocation('about', 'ja')) }}</span>
<span class="about-object-ja">{{ JSON.stringify(localeLocation({ name: 'about' }, 'ja')) }}</span>
<span class="path-match-ja">{{ JSON.stringify(localeLocation('/:pathMatch(.*)*', 'ja')) }}</span>
<span class="path-match-name">{{ JSON.stringify(localeLocation('pathMatch')) }}</span>
<span class="path-match-name-ja">{{ JSON.stringify(localeLocation('pathMatch', 'ja')) }}</span>
<span class="undefined-path-ja">{{ JSON.stringify(localeRoute('/vue-i18n', 'ja')) }}</span>
<span class="undefined-name-ja">{{ JSON.stringify(localeRoute('vue-i18n', 'ja')) }}</span>
</section>
</ClientOnly>
</div>
Expand Down