@@ -21,6 +21,7 @@ describe("event", () => {
2121 const id = text . id ;
2222 text . insert ( 0 , "123" ) ;
2323 loro . commit ( ) ;
24+ await oneMs ( ) ;
2425 expect ( lastEvent ?. target ) . toEqual ( id ) ;
2526 } ) ;
2627
@@ -41,14 +42,18 @@ describe("event", () => {
4142 const map = loro . getMap ( "map" ) ;
4243 map . set ( "0" , 100 ) ;
4344 loro . commit ( ) ;
45+ await oneMs ( ) ;
4446 expect ( uniqueEvent ) . toBe ( 1 ) ;
4547 const bDoc = new Loro ( ) ;
4648 bDoc . getText ( "text" ) . insert ( 0 , "1" ) ;
4749 bDoc . getText ( "text" ) . insert ( 1 , "1" ) ;
4850 bDoc . commit ( ) ;
51+ await oneMs ( ) ;
4952 bDoc . getMap ( "map" ) . set ( "0" , "1" ) ;
5053 bDoc . commit ( ) ;
54+ await oneMs ( ) ;
5155 loro . import ( bDoc . exportFrom ( ) ) ;
56+ await oneMs ( ) ;
5257 expect ( uniqueEvent ) . toBe ( 2 ) ;
5358 } ) ;
5459
@@ -62,14 +67,17 @@ describe("event", () => {
6267 const subMap = map . setContainer ( "sub" , "Map" ) ;
6368 subMap . set ( "0" , "1" ) ;
6469 loro . commit ( ) ;
70+ await oneMs ( ) ;
6571
6672 expect ( lastEvent ?. path ) . toStrictEqual ( [ "map" , "sub" ] ) ;
6773 const list = subMap . setContainer ( "list" , "List" ) ;
6874 list . insert ( 0 , "2" ) ;
6975 const text = list . insertContainer ( 1 , "Text" ) ;
7076 loro . commit ( ) ;
77+ await oneMs ( ) ;
7178 text . insert ( 0 , "3" ) ;
7279 loro . commit ( ) ;
80+ await oneMs ( ) ;
7381 expect ( lastEvent ?. path ) . toStrictEqual ( [ "map" , "sub" , "list" , 1 ] ) ;
7482 } ) ;
7583
@@ -82,12 +90,14 @@ describe("event", () => {
8290 const text = loro . getText ( "t" ) ;
8391 text . insert ( 0 , "3" ) ;
8492 loro . commit ( ) ;
93+ await oneMs ( ) ;
8594 expect ( lastEvent ?. diff ) . toStrictEqual ( {
8695 type : "text" ,
8796 diff : [ { insert : "3" } ] ,
8897 } as TextDiff ) ;
8998 text . insert ( 1 , "12" ) ;
9099 loro . commit ( ) ;
100+ await oneMs ( ) ;
91101 expect ( lastEvent ?. diff ) . toStrictEqual ( {
92102 type : "text" ,
93103 diff : [ { retain : 1 } , { insert : "12" } ] ,
@@ -103,12 +113,14 @@ describe("event", () => {
103113 const text = loro . getList ( "l" ) ;
104114 text . insert ( 0 , "3" ) ;
105115 loro . commit ( ) ;
116+ await oneMs ( ) ;
106117 expect ( lastEvent ?. diff ) . toStrictEqual ( {
107118 type : "list" ,
108119 diff : [ { insert : [ "3" ] } ] ,
109120 } as ListDiff ) ;
110121 text . insert ( 1 , "12" ) ;
111122 loro . commit ( ) ;
123+ await oneMs ( ) ;
112124 expect ( lastEvent ?. diff ) . toStrictEqual ( {
113125 type : "list" ,
114126 diff : [ { retain : 1 } , { insert : [ "12" ] } ] ,
@@ -125,6 +137,7 @@ describe("event", () => {
125137 map . set ( "0" , "3" ) ;
126138 map . set ( "1" , "2" ) ;
127139 loro . commit ( ) ;
140+ await oneMs ( ) ;
128141 expect ( lastEvent ?. diff ) . toStrictEqual ( {
129142 type : "map" ,
130143 updated : {
@@ -135,6 +148,7 @@ describe("event", () => {
135148 map . set ( "0" , "0" ) ;
136149 map . set ( "1" , "1" ) ;
137150 loro . commit ( ) ;
151+ await oneMs ( ) ;
138152 expect ( lastEvent ?. diff ) . toStrictEqual ( {
139153 type : "map" ,
140154 updated : {
@@ -161,8 +175,10 @@ describe("event", () => {
161175
162176 text . insert ( 0 , "123" ) ;
163177 loro . commit ( ) ;
178+ await oneMs ( ) ;
164179 text . insert ( 1 , "456" ) ;
165180 loro . commit ( ) ;
181+ await oneMs ( ) ;
166182 expect ( ran ) . toBeTruthy ( ) ;
167183 // subscribeOnce test
168184 expect ( text . toString ( ) ) . toEqual ( "145623" ) ;
@@ -172,6 +188,7 @@ describe("event", () => {
172188 text . unsubscribe ( loro , sub ) ;
173189 text . insert ( 0 , "789" ) ;
174190 loro . commit ( ) ;
191+ await oneMs ( ) ;
175192 expect ( ran ) . toBe ( oldRan ) ;
176193 } ) ;
177194
@@ -185,18 +202,22 @@ describe("event", () => {
185202
186203 const subMap = map . setContainer ( "sub" , "Map" ) ;
187204 loro . commit ( ) ;
205+ await oneMs ( ) ;
188206 expect ( times ) . toBe ( 1 ) ;
189207 const text = subMap . setContainer ( "k" , "Text" ) ;
190208 loro . commit ( ) ;
209+ await oneMs ( ) ;
191210 expect ( times ) . toBe ( 2 ) ;
192211 text . insert ( 0 , "123" ) ;
193212 loro . commit ( ) ;
213+ await oneMs ( ) ;
194214 expect ( times ) . toBe ( 3 ) ;
195215
196216 // unsubscribe
197217 loro . unsubscribe ( sub ) ;
198218 text . insert ( 0 , "123" ) ;
199219 loro . commit ( ) ;
220+ await oneMs ( ) ;
200221 expect ( times ) . toBe ( 3 ) ;
201222 } ) ;
202223
@@ -210,15 +231,18 @@ describe("event", () => {
210231
211232 const text = list . insertContainer ( 0 , "Text" ) ;
212233 loro . commit ( ) ;
234+ await oneMs ( ) ;
213235 expect ( times ) . toBe ( 1 ) ;
214236 text . insert ( 0 , "123" ) ;
237+ await oneMs ( ) ;
215238 loro . commit ( ) ;
216239 expect ( times ) . toBe ( 2 ) ;
217240
218241 // unsubscribe
219242 loro . unsubscribe ( sub ) ;
220243 text . insert ( 0 , "123" ) ;
221244 loro . commit ( ) ;
245+ await oneMs ( ) ;
222246 expect ( times ) . toBe ( 2 ) ;
223247 } ) ;
224248 } ) ;
@@ -250,23 +274,27 @@ describe("event", () => {
250274 } ) ;
251275 text . insert ( 0 , "你好" ) ;
252276 loro . commit ( ) ;
277+ await oneMs ( ) ;
253278 expect ( text . toString ( ) ) . toBe ( string ) ;
254279
255280 text . insert ( 1 , "世界" ) ;
256281 loro . commit ( ) ;
282+ await oneMs ( ) ;
257283 expect ( text . toString ( ) ) . toBe ( string ) ;
258284
259285 text . insert ( 2 , "👍" ) ;
260286 loro . commit ( ) ;
287+ await oneMs ( ) ;
261288 expect ( text . toString ( ) ) . toBe ( string ) ;
262289
263290 text . insert ( 2 , "♪(^∇^*)" ) ;
264291 loro . commit ( ) ;
292+ await oneMs ( ) ;
265293 expect ( text . toString ( ) ) . toBe ( string ) ;
266294 } ) ;
267295 } ) ;
268296} ) ;
269297
270- function zeroMs ( ) : Promise < void > {
298+ function oneMs ( ) : Promise < void > {
271299 return new Promise ( ( r ) => setTimeout ( r ) ) ;
272300}
0 commit comments