Hi,
I am trying to write some basic tests where I want to test my sync code. My sync logic subscribes to observeDeep
to listen to the events. But my tests do not work, so I made the following sample:
test('should remove property from object', () => {
const doc1 = new Y.Doc();
const doc2 = new Y.Doc();
const root1 = doc1.getMap();
const root2 = doc2.getMap();
doc1.transact(() => {
root1.set('Key', '1');
});
doc2.transact(() => {
root2.set('Key', '1');
});
doc1.on('update', (update: Uint8Array) => {
console.log('Update');
Y.logUpdate(update);
Y.applyUpdate(doc2, update);
});
root2.observeDeep((events: any) => {
console.log('EVENTS');
console.log(JSON.stringify(events, undefined, 2));
});
doc1.transact(() => {
root1.set('Key', '42');
});
});
If I comment the initial two set calls out, I get an event, otherwise I do not receive an event. So I am confused what I am actually doing wrong.
But I receive updates: