Skip to content

Commit a36d91b

Browse files
committed
test(rsc): test hydrateRoot(..., { formState })
1 parent e202342 commit a36d91b

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,39 @@ function defineTest(f: Fixture) {
238238
await testUseActionState(page)
239239
})
240240

241+
test('useActionState nojs to js', async ({ page }) => {
242+
// this test fails without `formState` passed to `hydrateRoot(..., { formState })`
243+
244+
// intercept request to disable js
245+
let js: boolean
246+
await page.route(f.url(), async (route) => {
247+
if (!js) {
248+
await route.continue({ url: route.request().url() + '?__nojs' })
249+
return
250+
}
251+
await route.continue()
252+
})
253+
254+
// no js
255+
js = false
256+
await page.goto(f.url())
257+
await expect(page.getByTestId('use-action-state')).toContainText(
258+
'test-useActionState: 0',
259+
)
260+
await page.getByTestId('use-action-state').click()
261+
await expect(page.getByTestId('use-action-state')).toContainText(
262+
'test-useActionState: 1',
263+
)
264+
265+
// with js (hydration)
266+
js = true
267+
await page.getByTestId('use-action-state').click()
268+
await waitForHydration(page)
269+
await expect(page.getByTestId('use-action-state')).toContainText(
270+
'test-useActionState: 2', // this becomes "0" without formState
271+
)
272+
})
273+
241274
async function testUseActionState(page: Page) {
242275
await expect(page.getByTestId('use-action-state')).toContainText(
243276
'test-useActionState: 0',

0 commit comments

Comments
 (0)