string.test.tsx
This file
Path
src/jsx/hooks/string.test.tsx
40 lines · 1.3 KiB · TypeScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than f0b094d point at it.
Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 1–40why, one step back1/** @jsxImportSource ../ */2import { useState, useSyncExternalStore } from '..'34describe('useState', () => {5 it('should be rendered with initial state', () => {6 const Component = () => {7 const [state] = useState('hello')8 return <span>{state}</span>9 }10 const template = <Component />11 expect(template.toString()).toBe('<span>hello</span>')12 })13})1415describe('useSyncExternalStore', () => {16 it('should be rendered with result of getServerSnapshot()', () => {17 const unsubscribe = vi.fn()18 const subscribe = vi.fn(() => unsubscribe)19 const getSnapshot = vi.fn()20 const getServerSnapshot = vi.fn(() => 100)21 const App = () => {22 const count = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)23 return <div>{count}</div>24 }25 const template = <App />26 expect(template.toString()).toBe('<div>100</div>')27 expect(unsubscribe).not.toBeCalled()28 expect(subscribe).not.toBeCalled()29 expect(getSnapshot).not.toBeCalled()30 })3132 it('should raise an error if getServerShot() is not provided', () => {33 const App = () => {34 const count = useSyncExternalStore(vi.fn(), vi.fn())35 return <div>{count}</div>36 }37 const template = <App />38 expect(() => template.toString()).toThrowError()39 })40})