riverpod icon indicating copy to clipboard operation
riverpod copied to clipboard

`whenData` of AsyncValue changes `isLoading` and `isRefreshing` to be `false`

Open mono0926 opened this issue 1 year ago • 0 comments

Describe the bug

whenData of AsyncValue changes isLoading and isRefreshing to be false.

To Reproduce

The commented out test below will fail. Is this intended behavior?

import 'package:riverpod/riverpod.dart';
import 'package:test/test.dart';

void main() {
  test('AsyncValue.when', () {
    final previous = AsyncValue<int>.data(1);

    final value = AsyncLoading<int>().copyWithPrevious(previous);
    expect(value.value, 1);
    expect(value, isA<AsyncData<int>>());
    expect(value.isLoading, isTrue);
    expect(value.isRefreshing, isTrue);

    final valueWhen = value.whenData((v) => v);
    expect(valueWhen.value, 1);
    expect(valueWhen, isA<AsyncData<int>>());
    // Failed
    /*
    expect(valueWhen.isLoading, isTrue);
    expect(valueWhen.isRefreshing, isTrue);
    */
  });
}

Expected behavior

This test above will be succeeded:

    expect(valueWhen.isLoading, isTrue);
    expect(valueWhen.isRefreshing, isTrue);

mono0926 avatar Aug 08 '22 11:08 mono0926