-
Notifications
You must be signed in to change notification settings - Fork 0
/
06_event.test.ts
30 lines (28 loc) · 979 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 { getType, LoroDoc, LoroMap, LoroText } from "npm:[email protected]";
import { expect } from "npm:[email protected]";
Deno.test("Event have delta that contains Container", async () => {
const doc = new LoroDoc();
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();
});