@@ -37,8 +37,6 @@ import {QuoteNode} from "@lexical/rich-text/LexicalQuoteNode";
3737import { DetailsNode } from "@lexical/rich-text/LexicalDetailsNode" ;
3838import { EditorUiContext } from "../../../../ui/framework/core" ;
3939import { EditorUIManager } from "../../../../ui/framework/manager" ;
40- import { turtle } from "@codemirror/legacy-modes/mode/turtle" ;
41-
4240
4341type TestEnv = {
4442 readonly container : HTMLDivElement ;
@@ -47,6 +45,9 @@ type TestEnv = {
4745 readonly innerHTML : string ;
4846} ;
4947
48+ /**
49+ * @deprecated - Consider using `createTestContext` instead within the test case.
50+ */
5051export function initializeUnitTest (
5152 runTests : ( testEnv : TestEnv ) => void ,
5253 editorConfig : CreateEditorArgs = { namespace : 'test' , theme : { } } ,
@@ -795,6 +796,30 @@ export function expectNodeShapeToMatch(editor: LexicalEditor, expected: nodeShap
795796 expect ( shape . children ) . toMatchObject ( expected ) ;
796797}
797798
799+ /**
800+ * Expect a given prop within the JSON editor state structure to be the given value.
801+ * Uses dot notation for the provided `propPath`. Example:
802+ * 0.5.cat => First child, Sixth child, cat property
803+ */
804+ export function expectEditorStateJSONPropToEqual ( editor : LexicalEditor , propPath : string , expected : any ) {
805+ let currentItem : any = editor . getEditorState ( ) . toJSON ( ) . root ;
806+ let currentPath = [ ] ;
807+ const pathParts = propPath . split ( '.' ) ;
808+
809+ for ( const part of pathParts ) {
810+ currentPath . push ( part ) ;
811+ const childAccess = Number . isInteger ( Number ( part ) ) && Array . isArray ( currentItem . children ) ;
812+ const target = childAccess ? currentItem . children : currentItem ;
813+
814+ if ( typeof target [ part ] === 'undefined' ) {
815+ throw new Error ( `Could not resolve editor state at path ${ currentPath . join ( '.' ) } ` )
816+ }
817+ currentItem = target [ part ] ;
818+ }
819+
820+ expect ( currentItem ) . toBe ( expected ) ;
821+ }
822+
798823function formatHtml ( s : string ) : string {
799824 return s . replace ( / > \s + < / g, '><' ) . replace ( / \s * \n \s * / g, ' ' ) . trim ( ) ;
800825}
0 commit comments