Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
phonzammi committed Feb 8, 2025
1 parent dcd8869 commit 28efa35
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/redux/.test-dev.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { testRun } from './.testRun'
testRun('pnpm run dev')
2 changes: 2 additions & 0 deletions examples/redux/.test-preview.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { testRun } from './.testRun'
testRun('pnpm run preview')
39 changes: 39 additions & 0 deletions examples/redux/.testRun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export { testRun }

import { test, expect, run, page, getServerUrl, autoRetry } from '@brillout/test-e2e'

function testRun(cmd: `pnpm run ${'dev' | 'preview'}`) {
run(cmd)

const content1 = 'This page is'
const content2 = 'The counter value is'

test('The store persists across page navigation', async () => {
let body: string | null

await page.goto(getServerUrl() + '/')
body = await page.textContent('body')

expect(body).toContain(content1)
await testCounter()

await page.click('a:has-text("About")')
await page.click('button')

body = await page.textContent('body')
expect(body).toContain(content2)
expect(await page.textContent('button')).toContain('Counter 2')
})
}

async function testCounter() {
// autoRetry() for awaiting client-side code loading & executing
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 28efa35

Please sign in to comment.