Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions packages/drift_sqlite_async/test/db_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ void main() {

test('watch', () async {
var stream = dbu.select(dbu.todoItems).watch();
var resultsPromise =
stream.distinct().skipWhile((e) => e.isEmpty).take(3).toList();
var resultsPromise = stream
// toString() so that we can use distinct()
.map((rows) => rows.toString())
// Drift may or may not emit duplicate update notifications.
// We use distinct() to ignore those.
.distinct()
.skipWhile((e) => e.isEmpty)
.take(3)
.toList();

await dbu.into(dbu.todoItems).insert(
TodoItemsCompanion.insert(id: Value(1), description: 'Test 1'));
Expand All @@ -65,16 +72,20 @@ void main() {
expect(
results,
equals([
[TodoItem(id: 1, description: 'Test 1')],
[TodoItem(id: 1, description: 'Test 1B')],
[]
'[TodoItem(id: 1, description: Test 1)]',
'[TodoItem(id: 1, description: Test 1B)]',
'[]'
]));
});

test('watch with external updates', () async {
var stream = dbu.select(dbu.todoItems).watch();
var resultsPromise =
stream.distinct().skipWhile((e) => e.isEmpty).take(3).toList();
var resultsPromise = stream
.map((rows) => rows.toString())
.distinct()
.skipWhile((e) => e.isEmpty)
.take(3)
.toList();

await db.execute(
'INSERT INTO todos(id, description) VALUES(?, ?)', [1, 'Test 1']);
Expand All @@ -88,9 +99,9 @@ void main() {
expect(
results,
equals([
[TodoItem(id: 1, description: 'Test 1')],
[TodoItem(id: 1, description: 'Test 1B')],
[]
'[TodoItem(id: 1, description: Test 1)]',
'[TodoItem(id: 1, description: Test 1B)]',
'[]'
]));
});
});
Expand Down
Loading