Skip to content

Commit

Permalink
Repro of #1823
Browse files Browse the repository at this point in the history
  • Loading branch information
dfahlander committed Nov 17, 2023
1 parent 47220cf commit 34ed018
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/tests-live-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,27 @@ promisedTest("subscribe and error occur", async ()=> {
subscription.unsubscribe();
});

promisedTest("optimistic updates that eventually fail must be reverted (Issue #1823)", async ()=>{
const log = [];
let subscription = liveQuery(
()=>db.items.toArray()
).subscribe({
next: result => {
log.push(result);
console.log("optimistic result (from #1823 test)", result);
},
});

await db.transaction('rw', db.items, async ()=>{
await db.items.add({id: 1, iWillFail: true}).catch(()=>{});
});
// Wait for a successful readonly transaction to complete after the write transaction.
// This will make sure that the liveQuery has been updated with the final result.
await db.transaction('r', db.items, ()=>db.items.toArray());
subscription.unsubscribe();
deepEqual(log.at(-1), [{id: 1},{id:2},{id:3}], "Last log entry contains the correct result. There might be optimistic updates before though.");
});

/* Use cases to cover:
Queries
Expand Down

0 comments on commit 34ed018

Please sign in to comment.