File tree Expand file tree Collapse file tree 4 files changed +76
-1
lines changed
examples/basic/src/routes Expand file tree Collapse file tree 4 files changed +76
-1
lines changed Original file line number Diff line number Diff line change @@ -355,6 +355,26 @@ function defineTest(f: Fixture) {
355355 )
356356 }
357357
358+ test ( 'non form action error @js' , async ( { page } ) => {
359+ await page . goto ( f . url ( ) )
360+ await waitForHydration ( page )
361+ await expect ( page . getByTestId ( 'non-form-action-error' ) ) . toContainText ( '?' )
362+ await page . getByTestId ( 'non-form-action-error' ) . click ( )
363+ await expect ( page . getByTestId ( 'non-form-action-error' ) ) . toContainText (
364+ 'non-form-action-error' ,
365+ )
366+ } )
367+
368+ test ( 'non form action args @js' , async ( { page } ) => {
369+ await page . goto ( f . url ( ) )
370+ await waitForHydration ( page )
371+ await expect ( page . getByTestId ( 'non-form-action-args' ) ) . toContainText ( '?' )
372+ await page . getByTestId ( 'non-form-action-args' ) . click ( )
373+ await expect ( page . getByTestId ( 'non-form-action-args' ) ) . toContainText (
374+ 'received: test-42' ,
375+ )
376+ } )
377+
358378 test ( 'useActionState with jsx @js' , async ( { page } ) => {
359379 await page . goto ( f . url ( ) )
360380 await waitForHydration ( page )
Original file line number Diff line number Diff line change @@ -25,3 +25,14 @@ export async function testAction2() {
2525export async function testActionState ( prev : number ) {
2626 return prev + 1
2727}
28+
29+ export async function testNonFormActionError ( ) {
30+ throw new Error ( 'non-form-action-error' )
31+ }
32+
33+ export async function testNonFormActionArgs ( data : {
34+ name : string
35+ count : number
36+ } ) {
37+ return `received: ${ data . name } -${ data . count } `
38+ }
Original file line number Diff line number Diff line change 11'use client'
22
33import React from 'react'
4- import { testAction , testAction2 , testActionState } from './action'
4+ import {
5+ testAction ,
6+ testAction2 ,
7+ testActionState ,
8+ testNonFormActionArgs ,
9+ testNonFormActionError ,
10+ } from './action'
511
612export function TestActionFromClient ( ) {
713 return (
@@ -23,3 +29,37 @@ export function TestUseActionState() {
2329 </ form >
2430 )
2531}
32+
33+ export function TestNonFormActionError ( ) {
34+ const [ state , setState ] = React . useState ( '?' )
35+ return (
36+ < button
37+ data-testid = "non-form-action-error"
38+ onClick = { async ( ) => {
39+ try {
40+ await testNonFormActionError ( )
41+ setState ( 'no-error' )
42+ } catch ( e ) {
43+ setState ( e instanceof Error ? e . message : 'unknown-error' )
44+ }
45+ } }
46+ >
47+ non-form-action-error: { state }
48+ </ button >
49+ )
50+ }
51+
52+ export function TestNonFormActionArgs ( ) {
53+ const [ state , setState ] = React . useState ( '?' )
54+ return (
55+ < button
56+ data-testid = "non-form-action-args"
57+ onClick = { async ( ) => {
58+ const result = await testNonFormActionArgs ( { name : 'test' , count : 42 } )
59+ setState ( result )
60+ } }
61+ >
62+ non-form-action-args: { state }
63+ </ button >
64+ )
65+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import {
1010import { TestServerActionError } from './action-error/server'
1111import {
1212 TestActionFromClient ,
13+ TestNonFormActionArgs ,
14+ TestNonFormActionError ,
1315 TestUseActionState ,
1416} from './action-from-client/client'
1517import { TestActionStateServer } from './action-state/server'
@@ -95,6 +97,8 @@ export function Root(props: { url: URL }) {
9597 < TestSuspense url = { props . url } />
9698 < TestActionFromClient />
9799 < TestUseActionState />
100+ < TestNonFormActionError />
101+ < TestNonFormActionArgs />
98102 < TestPayloadServer url = { props . url } />
99103 < TestServerActionBindReset />
100104 < TestServerActionBindSimple />
You can’t perform that action at this time.
0 commit comments