Skip to content

Commit 5013deb

Browse files
chore: fix racy web watch test
1 parent 1530190 commit 5013deb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/web/tests/watch.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,27 @@ describe('Watch Tests', { sequential: true }, () => {
671671
});
672672
onTestFinished(dispose);
673673

674+
// Wait for the initial load to complete
675+
await vi.waitFor(
676+
() => {
677+
expect(watch.state.isLoading).false;
678+
},
679+
{ timeout: 1000 }
680+
);
681+
682+
notificationCount = 0; // We want to count the number of state changes after the initial load
683+
674684
// Should only a state change trigger for this operation
675685
await powersync.execute('INSERT INTO assets(id, make, customer_id) VALUES (uuid(), ?, ?)', ['test', uuid()]);
676686

687+
// We should get an update for the change above
688+
await vi.waitFor(
689+
() => {
690+
expect(notificationCount).equals(1);
691+
},
692+
{ timeout: 1000 }
693+
);
694+
677695
// Should not trigger any state change for these operations
678696
await powersync.execute('INSERT INTO assets(id, make, customer_id) VALUES (uuid(), ?, ?)', ['make1', uuid()]);
679697
await powersync.execute('INSERT INTO assets(id, make, customer_id) VALUES (uuid(), ?, ?)', ['make2', uuid()]);

0 commit comments

Comments
 (0)