/* 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(

First:

Second:

) 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(

First:

Second:

Third:

) expect(getByText('First: V = 1')).toBeInTheDocument() expect(getByText('Second: V = 1')).toBeInTheDocument() expect(getByText('Third: V = 1')).toBeInTheDocument() }) })