Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Apr 8, 2024
1 parent 74daf53 commit 2271d54
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions examples/full/.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ runTest()
function runTest() {
run('pnpm run dev')

const textLandingPage = 'Rendered to HTML.'
testUrl({
url: '/',
title: 'My Vike + React App',
text: 'My Vike + React app',
text: textLandingPage,
counter: true
})

Expand All @@ -24,10 +25,11 @@ function runTest() {
text: '1983-05-25'
})

const textNoSSR = 'This page is rendered only in the browser'
{
const url = '/without-ssr'
const title = 'My Vike + React App'
const text = "It isn't rendered to HTML."
const text = textNoSSR
test(url + ' (HTML)', async () => {
const html = await fetchHtml(url)
// Isn't rendered to HTML
Expand All @@ -41,6 +43,24 @@ function runTest() {
const body = await page.textContent('body')
expect(body).toContain(text)
})
test('Switch between SSR and non-SSR page', async () => {
let body: string | null
const t1 = textNoSSR
const t2 = textLandingPage
body = await page.textContent('body')
expect(body).toContain(t1)
expect(body).not.toContain(t2)
await page.click('a:has-text("Welcome")')
await testCounter()
body = await page.textContent('body')
expect(body).toContain(t2)
expect(body).not.toContain(t1)
await page.click('a:has-text("Without SSR")')
await testCounter()
body = await page.textContent('body')
expect(body).toContain(t1)
expect(body).not.toContain(t2)
})
}
}

Expand All @@ -55,7 +75,6 @@ function testUrl({ url, title, text, counter }: { url: string; title: string; te
const body = await page.textContent('body')
expect(body).toContain(text)
if (counter) {
expect(await page.textContent('button')).toBe('Counter 0')
await testCounter()
}
})
Expand All @@ -68,8 +87,12 @@ function getTitle(html: string) {

async function testCounter() {
// autoRetry() for awaiting client-side code loading & executing
await autoRetry(async () => {
await page.click('button')
expect(await page.textContent('button')).toContain('Counter 1')
})
await autoRetry(
async () => {
expect(await page.textContent('button')).toBe('Counter 0')
await page.click('button')
expect(await page.textContent('button')).toContain('Counter 1')
},
{ timeout: 5 * 1000 }
)
}

0 comments on commit 2271d54

Please sign in to comment.