Skip to content

Commit 6976167

Browse files
hi-ogawaclaude
andauthored
test(plugin-rsc): add non-form action server action tests (#1080)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 454c742 commit 6976167

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

packages/plugin-rsc/e2e/basic.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

packages/plugin-rsc/examples/basic/src/routes/action-from-client/action.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,14 @@ export async function testAction2() {
2525
export 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+
}

packages/plugin-rsc/examples/basic/src/routes/action-from-client/client.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
'use client'
22

33
import 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

612
export 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+
}

packages/plugin-rsc/examples/basic/src/routes/root.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
import { TestServerActionError } from './action-error/server'
1111
import {
1212
TestActionFromClient,
13+
TestNonFormActionArgs,
14+
TestNonFormActionError,
1315
TestUseActionState,
1416
} from './action-from-client/client'
1517
import { 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 />

0 commit comments

Comments
 (0)