Skip to content

Commit cff2c53

Browse files
committed
Add complex forwarding test for async providers with manual invalidation
1 parent e752d80 commit cff2c53

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

packages/riverpod/test/src/core/ref_test.dart

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,6 +3131,65 @@ void main() {
31313131

31323132
sub.close();
31333133
});
3134+
3135+
test('complex forwarding scenario with async providers', () async {
3136+
final container = ProviderContainer.test();
3137+
final baseState = StateProvider((ref) => 0);
3138+
3139+
final asyncComputed = FutureProvider<int>((ref) {
3140+
final base = ref.watch(baseState);
3141+
return Future.value(base * 2);
3142+
});
3143+
3144+
final streamFamily = StreamProvider.family<String, int>((
3145+
ref,
3146+
id,
3147+
) async* {
3148+
final computed = await ref.watch(asyncComputed.future);
3149+
yield 'stream-$id-$computed';
3150+
});
3151+
3152+
final asyncNotifierProvider =
3153+
AsyncNotifierProvider<TestAsyncNotifier, int>(
3154+
TestAsyncNotifier.new,
3155+
);
3156+
3157+
final complexAsyncDerived = FutureProvider<String>((ref) async {
3158+
final base = ref.watch(baseState);
3159+
final computed = await ref.watch(asyncComputed.future);
3160+
final stream1 = await ref.watch(streamFamily(1).future);
3161+
final stream2 = await ref.watch(streamFamily(2).future);
3162+
final notifierValue = await ref.watch(asyncNotifierProvider.future);
3163+
3164+
ref.onManualInvalidation(() {
3165+
// Forward invalidation to multiple async providers
3166+
ref.invalidate(asyncComputed);
3167+
ref.invalidate(streamFamily(1));
3168+
ref.invalidate(streamFamily(2));
3169+
ref.invalidate(streamFamily);
3170+
ref.invalidate(asyncNotifierProvider);
3171+
});
3172+
3173+
return 'async-complex-$base-$computed-$stream1-$stream2-$notifierValue';
3174+
});
3175+
3176+
// Initialize all providers
3177+
final sub = container.listen(complexAsyncDerived, (prev, next) {});
3178+
await container.pump();
3179+
3180+
// Update base state to trigger dependency changes
3181+
container.read(baseState.notifier).state = 5;
3182+
await container.pump();
3183+
3184+
// Manual invalidation should work with async forwarding
3185+
expect(
3186+
() => container.invalidate(complexAsyncDerived),
3187+
returnsNormally,
3188+
);
3189+
await container.pump();
3190+
3191+
sub.close();
3192+
});
31343193
});
31353194
});
31363195

0 commit comments

Comments
 (0)