-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathbasic.test.ts
49 lines (37 loc) · 1.71 KB
/
basic.test.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
39
40
41
42
43
44
45
46
47
48
49
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { $fetch, getBrowser, setRuntimeConfig, setup, url } from '@nuxt/test-utils/e2e'
describe('ssr', async () => {
await setup({
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)),
browser: true,
})
it('renders the index page', async () => {
// Get response to a server-rendered page with `$fetch`.
const html = await $fetch('/')
expect(html).toContain('<span id="runtime">original value</span></div>')
})
it('changes runtime config client-side', async () => {
const browser = await getBrowser()
const page = await browser.newPage()
await page.goto(url('/'))
const el = page.locator('#runtime')
expect(await el.innerText()).to.equal('original value')
await page.evaluate(() => {
window.__NUXT_TEST_RUNTIME_CONFIG_SETTER__({ public: { myValue: 'overwritten by test!' } })
})
expect(await el.innerText()).to.equal('overwritten by test!')
})
it('changes runtime config in server route', async () => {
const originalConfig = await $fetch('/api/config')
expect(originalConfig.public.myValue).to.equal('original value')
await setRuntimeConfig({ public: { myValue: 'overwritten by test!' } })
const newConfig = await $fetch('/api/config')
expect(newConfig.public.myValue).to.equal('overwritten by test!')
})
it('changes runtime config', async () => {
expect(await $fetch('/')).toContain('<span id="runtime">original value</span></div>')
await setRuntimeConfig({ public: { myValue: 'overwritten by test!' } }, { restart: true })
expect(await $fetch('/')).toContain('<span id="runtime">overwritten by test!</span></div>')
})
})