test(notes): wait for the caret frame before typing in the numbered list test

This commit is contained in:
Maurice
2026-11-23 12:11:46 +01:00
parent 3ec7cc73b2
commit 965b519f23
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from 'vitest'
import { screen, waitFor } from '@testing-library/react'
import { act, screen, waitFor } from '@testing-library/react'
import { render } from '../../../tests/helpers/render'
import userEvent from '@testing-library/user-event'
import { useRef, useState } from 'react'
@@ -83,7 +83,9 @@ describe('NoteFormatToolbar', () => {
for (const [i, item] of ['Breakfast', 'Lunch', 'Dinner'].entries()) {
if (i > 0) await user.keyboard('{Enter}')
await user.click(numbered)
await waitFor(() => expect(field().selectionStart).toBe(field().value.length))
// The toolbar puts the caret back one frame later; typing before that
// frame would have it jump into the middle of the word.
await act(() => new Promise<void>(resolve => requestAnimationFrame(() => resolve())))
await user.keyboard(item)
}