fix type errors in tests

This commit is contained in:
Mel Bourgeois 2024-02-24 20:51:31 -06:00
parent c9995bda17
commit 8c1d7c72b8
No known key found for this signature in database
GPG Key ID: 290FCF081AEDB3EC
2 changed files with 10 additions and 6 deletions

View File

@ -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<Record<string, Y.Doc>>} */
const mysubdocs = doc2.getMap('mysubdocs')
mysubdocs.get('a')?.load()
t.compare(event, [[], [], ['a']])
t.compare(Array.from(doc2.getSubdocGuids()), ['a', 'c'])

View File

@ -448,6 +448,7 @@ export const testUndoNestedUndoIssue = _tc => {
*/
export const testConsecutiveRedoBug = _tc => {
const doc = new Y.Doc()
/** @type {Y.Map<Record<string, Y.Map<any>>>} */
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