Download slate/packages/slate-react/test/use-slate.spec.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/slate/packages/slate-react/test/use-slate.spec.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/slate/packages/slate-react/test/use-slate.spec.tsx
-
curl -L -o use-slate.spec.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/slate/packages/slate-react/test/use-slate.spec.tsx
1.71 kB
| /* eslint-disable import/no-deprecated */ | |
| import React from 'react' | |
| import { Transforms, createEditor } from 'slate' | |
| import { render, act } from '@testing-library/react' | |
| import '@testing-library/jest-dom' | |
| import { Slate, withReact, Editable, useSlateWithV } from '../src' | |
| describe('useSlateWithV', () => { | |
| const ShowVersion = () => { | |
| const { v } = useSlateWithV() | |
| return <>V = {v}</> | |
| } | |
| it('tracks a global `v` counter for the editor', async () => { | |
| const editor = withReact(createEditor()) | |
| const initialValue = [{ type: 'block', children: [{ text: 'test' }] }] | |
| const { getByText, rerender } = render( | |
| <Slate editor={editor} initialValue={initialValue}> | |
| <Editable /> | |
| <p> | |
| First: <ShowVersion key={1} /> | |
| </p> | |
| <p> | |
| Second: <ShowVersion key={2} /> | |
| </p> | |
| </Slate> | |
| ) | |
| expect(getByText('First: V = 0')).toBeInTheDocument() | |
| expect(getByText('Second: V = 0')).toBeInTheDocument() | |
| await act(async () => { | |
| Transforms.insertText(editor, '!', { at: { path: [0, 0], offset: 4 } }) | |
| }) | |
| expect(getByText('First: V = 1')).toBeInTheDocument() | |
| expect(getByText('Second: V = 1')).toBeInTheDocument() | |
| rerender( | |
| <Slate editor={editor} initialValue={initialValue}> | |
| <Editable /> | |
| <p> | |
| First: <ShowVersion key={1} /> | |
| </p> | |
| <p> | |
| Second: <ShowVersion key={2} /> | |
| </p> | |
| <p> | |
| Third: <ShowVersion key={3} /> | |
| </p> | |
| </Slate> | |
| ) | |
| expect(getByText('First: V = 1')).toBeInTheDocument() | |
| expect(getByText('Second: V = 1')).toBeInTheDocument() | |
| expect(getByText('Third: V = 1')).toBeInTheDocument() | |
| }) | |
| }) | |