[lexical] Chore: Migrate LexicalSelection tests to buildEditorFromExtensions - #8865
Merged
Merged
Conversation
…ensions Convert all 15 initializeUnitTest blocks in LexicalSelection.test.ts to the modern buildEditorFromExtensions + using pattern. No behavioral change — pure infrastructure modernization. - Replace React-rendered test editors with headless buildEditorFromExtensions - Create shared selectionTestExtension (LinkExtension + ListExtension + test nodes) - Simplify insertText helpers to capture editor/container from closure scope - Adjust innerHTML assertions to remove the React wrapper div - Use LexicalEditorWithDispose for describe blocks that call Symbol.dispose
- Replace expect($isXxx(...)).toBe(true) with assert($isXxx(...)) for type narrowing (6 instances) - Convert text-type anchor.set/focus.set pairs to setTextNodeRange (12 cross-node pairs) - Simplify same-node selections to node.select(start, end) (8 instances) - Element-type and mixed anchor/focus points remain as-is (no replacement API)
- Replace LexicalEditor type with LexicalEditorWithDispose + Symbol.dispose in top-level describe
- Convert nested ternary to object lookup in inline element setup
- Add {discrete: true} to insertText() test
- Modernize facebook#6701 regression test to use buildEditorFromExtensions
- Replace with assert() pattern (15 instances)
- Unify all invariant() calls to vitest assert() for consistency (44 instances)
- Simplify cross-node selection creation: node.select(0,0).setTextNodeRange() (9 instances)
- Extract shared setup for getNodes()/extract() into parent describe
- Remove redundant await on {discrete: true} updates
mayrang
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
July 20, 2026 13:32
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
LexicalSelection.test.tsstill used the legacyinitializeUnitTestpattern — a React-rendering harness withtestEnv.editor, a wrapper<div>, and implicitbeforeEach/afterEach. This PR replaces all 15initializeUnitTestblocks with the headlessbuildEditorFromExtensions+usingpattern (or sharedlet editor+beforeEach/afterEachwhere tests need common state).Along the way, several stale patterns got cleaned up:
expect($isFoo(x)).toBe(true)→assert($isFoo(x))(vitest type-narrowing assert)anchor.set/focus.setpairs →setTextNodeRange()ornode.select()$assertRangeSelection($getSelection())→assert($isRangeSelection(selection))$createRangeSelection()+setTextNodeRange()+$setSelection()→node.select(0, 0).setTextNodeRange()beforeEachsetup betweengetNodes()andextract()→ shared parent describecreateEditorin the Bug: Pasting into custom inline ElementNode fails #6701 regression test →buildEditorFromExtensionsawaiton{discrete: true}updatesNet −92 lines. All 78 tests pass unchanged.
Test plan
pnpm test-unit -- LexicalSelection.test.ts— 78 pass