From f0655024ca7cfce5283fd068fe16c3c6181c1d36 Mon Sep 17 00:00:00 2001 From: yile Date: Wed, 27 Apr 2022 11:43:13 +0800 Subject: [PATCH] Test: RxDocument reference bug --- test/unit/bug-report.test.ts | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/unit/bug-report.test.ts b/test/unit/bug-report.test.ts index e71df75d898..20b3815b247 100644 --- a/test/unit/bug-report.test.ts +++ b/test/unit/bug-report.test.ts @@ -130,4 +130,54 @@ describe('bug-report.test.js', () => { db.destroy(); dbInOtherTab.destroy(); }); + + it('use findOne().$ to subscribe a document, the reference should equal to document which created by newDocument', async () => { + // generate a random database-name + const name = randomCouchString(10); + + // create a schema + const mySchema = { + version: 0, + primaryKey: 'id', + type: 'object', + properties: { + id: { + type: 'string', + maxLength: 100, + }, + name: { + type: 'string' + } + }, + }; + + // create a database + const db = await createRxDatabase({ + name, + /** + * By calling config.storage.getStorage(), + * we can ensure that all variations of RxStorage are tested in the CI. + */ + storage: config.storage.getStorage(), + eventReduce: true, + ignoreDuplicate: true + }); + // create a collection + await db.addCollections({ + mycollection: { + schema: mySchema + } + }); + + let docOuter; + db.mycollection.findOne('1').$.subscribe((doc) => (docOuter = doc)); + + const docNew = db.mycollection.newDocument({ id: '1', name: 'name-1' }); + + await docNew.save(); + + console.log('docOuter: ', docOuter) + + assert.strictEqual(docOuter === docNew, true) + }) });