From 8c1d7c72b81c75814a0c1e706f345c7d3bf9e8bc Mon Sep 17 00:00:00 2001 From: Mel Bourgeois Date: Sat, 24 Feb 2024 20:51:31 -0600 Subject: [PATCH] fix type errors in tests --- tests/doc.tests.js | 13 ++++++++----- tests/undo-redo.tests.js | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/doc.tests.js b/tests/doc.tests.js index bb94819d..77cac8e4 100644 --- a/tests/doc.tests.js +++ b/tests/doc.tests.js @@ -114,6 +114,7 @@ export const testSubdoc = _tc => { doc.on('subdocs', subdocs => { event = [Array.from(subdocs.added).map(x => x.guid), Array.from(subdocs.removed).map(x => x.guid), Array.from(subdocs.loaded).map(x => x.guid)] }) + /** @type {Y.Map<{ a: Y.Doc; b: Y.Doc, c: Y.Doc; }>} */ const subdocs = doc.getMap('mysubdocs') const docA = new Y.Doc({ guid: 'a' }) docA.load() @@ -121,18 +122,18 @@ export const testSubdoc = _tc => { t.compare(event, [['a'], [], ['a']]) event = null - subdocs.get('a').load() + subdocs.get('a')?.load() t.assert(event === null) event = null - subdocs.get('a').destroy() + subdocs.get('a')?.destroy() t.compare(event, [['a'], ['a'], []]) - subdocs.get('a').load() + subdocs.get('a')?.load() t.compare(event, [[], [], ['a']]) subdocs.set('b', new Y.Doc({ guid: 'a', shouldLoad: false })) t.compare(event, [['a'], [], []]) - subdocs.get('b').load() + subdocs.get('b')?.load() t.compare(event, [[], [], ['a']]) const docC = new Y.Doc({ guid: 'c' }) @@ -156,7 +157,9 @@ export const testSubdoc = _tc => { Y.applyUpdate(doc2, Y.encodeStateAsUpdate(doc)) t.compare(event, [['a', 'a', 'c'], [], []]) - doc2.getMap('mysubdocs').get('a').load() + /** @type {Y.Map>} */ + const mysubdocs = doc2.getMap('mysubdocs') + mysubdocs.get('a')?.load() t.compare(event, [[], [], ['a']]) t.compare(Array.from(doc2.getSubdocGuids()), ['a', 'c']) diff --git a/tests/undo-redo.tests.js b/tests/undo-redo.tests.js index 27636aff..29d8e1ff 100644 --- a/tests/undo-redo.tests.js +++ b/tests/undo-redo.tests.js @@ -448,6 +448,7 @@ export const testUndoNestedUndoIssue = _tc => { */ export const testConsecutiveRedoBug = _tc => { const doc = new Y.Doc() + /** @type {Y.Map>>} */ const yRoot = doc.getMap() const undoMgr = new Y.UndoManager(yRoot) @@ -481,7 +482,7 @@ export const testConsecutiveRedoBug = _tc => { t.compare(yRoot.get('a'), undefined) undoMgr.redo() // x=0, y=0 - yPoint = yRoot.get('a') + yPoint = yRoot.get('a') || new Y.Map() t.compare(yPoint.toJSON(), { x: 0, y: 0 }) undoMgr.redo() // x=100, y=100