forked from nuxt-modules/i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocale_fallback.spec.ts
38 lines (31 loc) · 1.2 KB
/
locale_fallback.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { test, expect } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, url, createPage } from './utils'
import { getText, getData } from './helper'
await setup({
rootDir: fileURLToPath(new URL(`./fixtures/fallback`, import.meta.url)),
browser: true,
// overrides
nuxtConfig: {
i18n: {}
}
})
test('fallback to target lang', async () => {
const home = url('/')
const page = await createPage()
await page.goto(home)
// `en` rendering
expect(await getText(page, '#home-header')).toEqual('Homepage')
expect(await getText(page, 'title')).toEqual('Homepage')
expect(await getText(page, '#link-about')).toEqual('About us')
// click `ja` lang switch with `<NuxtLink>`
await page.locator('#lang-switcher-with-nuxt-link-ja a').click()
// fallback to en content translation
expect(await getText(page, '#home-header')).toEqual('Homepage')
expect(await getText(page, 'title')).toEqual('Homepage')
expect(await getText(page, '#link-about')).toEqual('About us')
// page path
expect(await getData(page, '#home-use-async-data')).toMatchObject({ aboutPath: '/ja/about' })
// current locale
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('ja')
})