From 8f159e8dca6cc00676b4563669ba8971305e88bf Mon Sep 17 00:00:00 2001 From: Ricardo Boss Date: Tue, 20 Feb 2024 02:59:08 +0100 Subject: [PATCH] Added test for subscriptions --- test/store/in_memory_backing_store_test.dart | 29 ++++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/test/store/in_memory_backing_store_test.dart b/test/store/in_memory_backing_store_test.dart index 39ea69c..2f36ad3 100644 --- a/test/store/in_memory_backing_store_test.dart +++ b/test/store/in_memory_backing_store_test.dart @@ -103,20 +103,25 @@ void main() { bStore.set('cModel', cModel); }); - test('returns only changed values', () + test('subscriptions get notified', () { - final store = InMemoryBackingStore() - ..set('name', 'Peter') - ..set('email', 'peter@neverland.com') - ..returnOnlyChangedValues = true; - - final changedEntries = store.iterate().toList(); - expect(changedEntries, hasLength(0)); - - store.set('name', 'Wendy'); + final store = InMemoryBackingStore(); - final changedEntries2 = store.iterate().toList(); - expect(changedEntries2, hasLength(1)); + String? key; + Object? oldValue; + Object? newValue; + final subscriptionId = store.subscribe((k, a, b) { + key = k; + oldValue = a; + newValue = b; + }); + + store.set('name', 'Peter'); + + expect(key, 'name'); + expect(oldValue, null); + expect(newValue, 'Peter'); + expect(subscriptionId, isNotNull); }); }); }