@@ -20,40 +20,42 @@ it("can fork a document", async () => {
2020 } ,
2121 } ) ;
2222
23- const div = document . createElement ( "div" ) ;
24- editor . mount ( div ) ;
25-
26- editor . replaceBlocks ( editor . document , [
27- {
28- type : "paragraph" ,
29- content : [ { text : "Hello" , styles : { } , type : "text" } ] ,
30- } ,
31- ] ) ;
32-
33- await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
34- "__snapshots__/fork-yjs-snap.html" ,
35- ) ;
36- await expect ( editor . document ) . toMatchFileSnapshot (
37- "__snapshots__/fork-yjs-snap-editor.json" ,
38- ) ;
39-
40- editor . getExtension ( ForkYDocExtension ) ! . fork ( ) ;
23+ try {
24+ const div = document . createElement ( "div" ) ;
25+ editor . mount ( div ) ;
26+
27+ editor . replaceBlocks ( editor . document , [
28+ {
29+ type : "paragraph" ,
30+ content : [ { text : "Hello" , styles : { } , type : "text" } ] ,
31+ } ,
32+ ] ) ;
4133
42- editor . replaceBlocks ( editor . document , [
43- {
44- type : "paragraph" ,
45- content : [ { text : "Hello World" , styles : { } , type : "text" } ] ,
46- } ,
47- ] ) ;
34+ await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
35+ "__snapshots__/fork-yjs-snap.html" ,
36+ ) ;
37+ await expect ( editor . document ) . toMatchFileSnapshot (
38+ "__snapshots__/fork-yjs-snap-editor.json" ,
39+ ) ;
4840
49- await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
50- "__snapshots__/fork-yjs-snap.html" ,
51- ) ;
52- await expect ( editor . document ) . toMatchFileSnapshot (
53- "__snapshots__/fork-yjs-snap-editor-forked.json" ,
54- ) ;
41+ editor . getExtension ( ForkYDocExtension ) ! . fork ( ) ;
5542
56- editor . unmount ( ) ;
43+ editor . replaceBlocks ( editor . document , [
44+ {
45+ type : "paragraph" ,
46+ content : [ { text : "Hello World" , styles : { } , type : "text" } ] ,
47+ } ,
48+ ] ) ;
49+
50+ await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
51+ "__snapshots__/fork-yjs-snap.html" ,
52+ ) ;
53+ await expect ( editor . document ) . toMatchFileSnapshot (
54+ "__snapshots__/fork-yjs-snap-editor-forked.json" ,
55+ ) ;
56+ } finally {
57+ editor . unmount ( ) ;
58+ }
5759} ) ;
5860
5961it ( "can merge a document" , async ( ) => {
@@ -69,49 +71,51 @@ it("can merge a document", async () => {
6971 } ,
7072 } ) ;
7173
72- const div = document . createElement ( "div" ) ;
73- editor . mount ( div ) ;
74-
75- editor . replaceBlocks ( editor . document , [
76- {
77- type : "paragraph" ,
78- content : [ { text : "Hello" , styles : { } , type : "text" } ] ,
79- } ,
80- ] ) ;
81-
82- await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
83- "__snapshots__/fork-yjs-snap.html" ,
84- ) ;
85- await expect ( editor . document ) . toMatchFileSnapshot (
86- "__snapshots__/fork-yjs-snap-editor.json" ,
87- ) ;
88-
89- editor . getExtension ( ForkYDocExtension ) ! . fork ( ) ;
74+ try {
75+ const div = document . createElement ( "div" ) ;
76+ editor . mount ( div ) ;
9077
91- editor . replaceBlocks ( editor . document , [
92- {
93- type : "paragraph" ,
94- content : [ { text : "Hello World" , styles : { } , type : "text" } ] ,
95- } ,
96- ] ) ;
97-
98- await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
99- "__snapshots__/fork-yjs-snap.html" ,
100- ) ;
101- await expect ( editor . document ) . toMatchFileSnapshot (
102- "__snapshots__/fork-yjs-snap-editor-forked.json" ,
103- ) ;
78+ editor . replaceBlocks ( editor . document , [
79+ {
80+ type : "paragraph" ,
81+ content : [ { text : "Hello" , styles : { } , type : "text" } ] ,
82+ } ,
83+ ] ) ;
10484
105- editor . getExtension ( ForkYDocExtension ) ! . merge ( { keepChanges : false } ) ;
85+ await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
86+ "__snapshots__/fork-yjs-snap.html" ,
87+ ) ;
88+ await expect ( editor . document ) . toMatchFileSnapshot (
89+ "__snapshots__/fork-yjs-snap-editor.json" ,
90+ ) ;
10691
107- await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
108- "__snapshots__/fork-yjs-snap.html" ,
109- ) ;
110- await expect ( editor . document ) . toMatchFileSnapshot (
111- "__snapshots__/fork-yjs-snap-editor.json" ,
112- ) ;
92+ editor . getExtension ( ForkYDocExtension ) ! . fork ( ) ;
11393
114- editor . unmount ( ) ;
94+ editor . replaceBlocks ( editor . document , [
95+ {
96+ type : "paragraph" ,
97+ content : [ { text : "Hello World" , styles : { } , type : "text" } ] ,
98+ } ,
99+ ] ) ;
100+
101+ await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
102+ "__snapshots__/fork-yjs-snap.html" ,
103+ ) ;
104+ await expect ( editor . document ) . toMatchFileSnapshot (
105+ "__snapshots__/fork-yjs-snap-editor-forked.json" ,
106+ ) ;
107+
108+ editor . getExtension ( ForkYDocExtension ) ! . merge ( { keepChanges : false } ) ;
109+
110+ await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
111+ "__snapshots__/fork-yjs-snap.html" ,
112+ ) ;
113+ await expect ( editor . document ) . toMatchFileSnapshot (
114+ "__snapshots__/fork-yjs-snap-editor.json" ,
115+ ) ;
116+ } finally {
117+ editor . unmount ( ) ;
118+ }
115119} ) ;
116120
117121it ( "can fork an keep the changes to the original document" , async ( ) => {
@@ -127,47 +131,49 @@ it("can fork an keep the changes to the original document", async () => {
127131 } ,
128132 } ) ;
129133
130- const div = document . createElement ( "div" ) ;
131- editor . mount ( div ) ;
132-
133- editor . replaceBlocks ( editor . document , [
134- {
135- type : "paragraph" ,
136- content : [ { text : "Hello" , styles : { } , type : "text" } ] ,
137- } ,
138- ] ) ;
139-
140- await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
141- "__snapshots__/fork-yjs-snap.html" ,
142- ) ;
143- await expect ( editor . document ) . toMatchFileSnapshot (
144- "__snapshots__/fork-yjs-snap-editor.json" ,
145- ) ;
134+ try {
135+ const div = document . createElement ( "div" ) ;
136+ editor . mount ( div ) ;
146137
147- editor . getExtension ( ForkYDocExtension ) ! . fork ( ) ;
148-
149- editor . replaceBlocks ( editor . document , [
150- {
151- type : "paragraph" ,
152- content : [ { text : "Hello World" , styles : { } , type : "text" } ] ,
153- } ,
154- ] ) ;
155-
156- await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
157- "__snapshots__/fork-yjs-snap.html" ,
158- ) ;
159- await expect ( editor . document ) . toMatchFileSnapshot (
160- "__snapshots__/fork-yjs-snap-editor-forked.json" ,
161- ) ;
138+ editor . replaceBlocks ( editor . document , [
139+ {
140+ type : "paragraph" ,
141+ content : [ { text : "Hello" , styles : { } , type : "text" } ] ,
142+ } ,
143+ ] ) ;
162144
163- editor . getExtension ( ForkYDocExtension ) ! . merge ( { keepChanges : true } ) ;
145+ await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
146+ "__snapshots__/fork-yjs-snap.html" ,
147+ ) ;
148+ await expect ( editor . document ) . toMatchFileSnapshot (
149+ "__snapshots__/fork-yjs-snap-editor.json" ,
150+ ) ;
164151
165- await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
166- "__snapshots__/fork-yjs-snap-forked.html" ,
167- ) ;
168- await expect ( editor . document ) . toMatchFileSnapshot (
169- "__snapshots__/fork-yjs-snap-editor-forked.json" ,
170- ) ;
152+ editor . getExtension ( ForkYDocExtension ) ! . fork ( ) ;
171153
172- editor . unmount ( ) ;
154+ editor . replaceBlocks ( editor . document , [
155+ {
156+ type : "paragraph" ,
157+ content : [ { text : "Hello World" , styles : { } , type : "text" } ] ,
158+ } ,
159+ ] ) ;
160+
161+ await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
162+ "__snapshots__/fork-yjs-snap.html" ,
163+ ) ;
164+ await expect ( editor . document ) . toMatchFileSnapshot (
165+ "__snapshots__/fork-yjs-snap-editor-forked.json" ,
166+ ) ;
167+
168+ editor . getExtension ( ForkYDocExtension ) ! . merge ( { keepChanges : true } ) ;
169+
170+ await expect ( fragment . toJSON ( ) ) . toMatchFileSnapshot (
171+ "__snapshots__/fork-yjs-snap-forked.html" ,
172+ ) ;
173+ await expect ( editor . document ) . toMatchFileSnapshot (
174+ "__snapshots__/fork-yjs-snap-editor-forked.json" ,
175+ ) ;
176+ } finally {
177+ editor . unmount ( ) ;
178+ }
173179} ) ;
0 commit comments