fix actions-navigation deploy test (#66850)

Switches to reading action result from state rather than runtime logs.
This commit is contained in:
Zack Tanner 2024-06-13 16:57:26 -07:00 committed by GitHub
parent 4dd26753d9
commit 02de207967
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 8 deletions

View file

@ -36,7 +36,6 @@
"test/e2e/app-dir/mdx/mdx.test.ts",
"test/e2e/app-dir/modularizeimports/modularizeimports.test.ts",
"test/e2e/app-dir/third-parties/basic.test.ts",
"test/e2e/app-dir/actions-navigation/index.test.ts",
"test/e2e/app-dir/app-static/app-static-custom-handler.test.ts",
"test/e2e/app-dir/options-request/options-request.test.ts",
"test/e2e/app-dir/revalidate-dynamic/revalidate-dynamic.test.ts",

View file

@ -1,5 +1,5 @@
'use server'
export async function addToCart() {
console.log('addToCart')
return 'Added to cart!'
}

View file

@ -1,5 +1,5 @@
'use client'
import { useFormStatus } from 'react-dom'
import { useFormStatus, useFormState } from 'react-dom'
import { addToCart } from './actions'
function SubmitButton() {
@ -13,10 +13,12 @@ function SubmitButton() {
}
export default function Page() {
const [state, formAction] = useFormState(addToCart)
return (
<>
<h1>Add to cart</h1>
<form action={addToCart}>
{state && <div id="result">{state}</div>}
<form action={formAction}>
<SubmitButton />
</form>
</>

View file

@ -1,5 +1,5 @@
import { nextTestSetup } from 'e2e-utils'
import { check, waitFor } from 'next-test-utils'
import { check, waitFor, retry } from 'next-test-utils'
describe('app-dir action handling', () => {
const { next } = nextTestSetup({
@ -40,8 +40,8 @@ describe('app-dir action handling', () => {
await browser.elementByCss('button').click()
await check(() => {
return (next.cliOutput.match(/addToCart/g) || []).length
}, 1)
await retry(async () => {
expect(await browser.elementById('result').text()).toBe('Added to cart!')
})
})
})