-
-
Notifications
You must be signed in to change notification settings - Fork 283
test(ssr): add SSR and hydration tests for 'getServerSnapshot' #1209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
f1ddb98
49104ce
3aea407
a5c4d42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { StrictMode, useEffect, useLayoutEffect, useState } from 'react' | ||
| import { act, fireEvent, render, screen } from '@testing-library/react' | ||
| import { renderToString } from 'react-dom/server' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { proxy, snapshot, useSnapshot } from 'valtio' | ||
| import { useCommitCount } from './utils' | ||
|
|
@@ -13,6 +14,24 @@ describe('basic', () => { | |
| vi.useRealTimers() | ||
| }) | ||
|
|
||
| it('should return snapshot via getServerSnapshot with renderToString', () => { | ||
| const obj = proxy({ count: 0 }) | ||
|
|
||
| const Counter = () => { | ||
| const snap = useSnapshot(obj) | ||
| return <div>count: {snap.count}</div> | ||
| } | ||
|
|
||
| const view = renderToString( | ||
| <StrictMode> | ||
| <Counter /> | ||
| </StrictMode>, | ||
| ) | ||
|
|
||
| expect(view).toContain('count:') | ||
| expect(view).toContain('0') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test still passes even if we remove getServerSnapshot.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dai-shi I verified by removing
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, but this test doesn't cover the behavior of getServerSnapshot. For example, if we have the getServerSnapshot implementation identical to that of getSnapshot, the test may pass.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dai-shi You're right — this test doesn't distinguish the behavior of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }) | ||
|
|
||
| it('simple counter', async () => { | ||
| const obj = proxy({ count: 0 }) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.