-
Notifications
You must be signed in to change notification settings - Fork 0
/
06_event.test.ts
30 lines (28 loc) · 972 Bytes
/
06_event.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Loro, LoroMap, LoroText, getType } from "npm:loro-crdt@0.16.4-alpha.0";
import { expect } from "npm:expect@29.7.0";
Deno.test("Event have delta that contains Container", async () => {
const doc = new Loro();
const list = doc.getList("list");
let ran = false;
doc.subscribe(events => {
for (const event of events.events) {
if (event.diff.type === "list") {
for (const item of event.diff.diff) {
expect(item.insert?.length).toBe(2);
expect(getType(item.insert![0])).toBe("Text")
expect(getType(item.insert![1])).toBe("Map")
const t = item.insert![0] as LoroText;
expect(t.toString()).toBe("Hello")
}
ran = true;
}
}
})
list.insertContainer(0, new LoroMap());
const t = list.insertContainer(0, new LoroText());
t.insert(0, "He");
t.insert(2, "llo");
doc.commit();
await new Promise(resolve => setTimeout(resolve, 1));
expect(ran).toBeTruthy()
})