Skip to content

Commit

Permalink
Unify "use cache" closure client component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Nov 7, 2024
1 parent 5068bdd commit 47211ad
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 52 deletions.
27 changes: 0 additions & 27 deletions test/e2e/app-dir/use-cache/app/passed-to-client-closure/page.tsx

This file was deleted.

7 changes: 4 additions & 3 deletions test/e2e/app-dir/use-cache/app/passed-to-client/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ function getRandomValue() {
}

export default function Page() {
const offset = 100
return (
<Form
foo={async function fooNamed() {
'use cache'
return getRandomValue()
return offset + getRandomValue()
}}
bar={async function () {
'use cache'
return getRandomValue()
return offset + getRandomValue()
}}
baz={async () => {
'use cache'
return getRandomValue()
return offset + getRandomValue()
}}
/>
)
Expand Down
22 changes: 0 additions & 22 deletions test/e2e/app-dir/use-cache/use-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,28 +160,6 @@ describe('use-cache', () => {

let threeRandomValues: string

await retry(async () => {
threeRandomValues = await browser.elementByCss('p').text()
expect(threeRandomValues).toMatch(/\d\.\d+ \d\.\d+ \d\.\d+/)
})

await browser.elementById('reset-button').click()
expect(await browser.elementByCss('p').text()).toBe('0 0 0')

await browser.elementById('submit-button').click()

await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe(threeRandomValues)
})
})

it('should cache results for cached closures passed to client components', async () => {
const browser = await next.browser('/passed-to-client-closure')
expect(await browser.elementByCss('p').text()).toBe('0 0 0')
await browser.elementById('submit-button').click()

let threeRandomValues: string

await retry(async () => {
threeRandomValues = await browser.elementByCss('p').text()
expect(threeRandomValues).toMatch(/100\.\d+ 100\.\d+ 100\.\d+/)
Expand Down

0 comments on commit 47211ad

Please sign in to comment.