GithubHelp home page GithubHelp logo

Comments (4)

rrousselGit avatar rrousselGit commented on May 30, 2024

The code given works fine on dartpad.
Riverpod tests heavily rely on using == on AsyncValue. I'd be surprised if that didn't work.

from riverpod.

Randomguy01 avatar Randomguy01 commented on May 30, 2024

Here is a more complete example of my issue:

items_provider.dart

import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'item.dart';
part 'items_provider.g.dart';

@riverpod
class Items extends _$Items {
  @override
  Future<List<Item>> build(ItemType itemType) async {
    return await Future.delayed(const Duration(milliseconds: 500), () => []);
  }
}

item.dart

class Item {
  const Item({required this.id, required this.name, required this.itemType});

  final int id;
  final String name;
  final ItemType itemType;
}

enum ItemType { a, b, c }

items_provider_test.dart

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:value_or_null/item.dart';
import 'package:value_or_null/items_provider.dart';

class Listener extends Mock {
  void call(AsyncValue<List<Item>>? previous, AsyncValue<List<Item>> next);
}

void main() {
  test("Test", () async {
    final container = ProviderContainer();
    addTearDown(container.dispose);
    final listener = Listener();

    container.listen(
      itemsProvider(ItemType.a),
      listener,
    );

    await Future.delayed(const Duration(seconds: 1));

    logInvocations([listener]);
    verify(listener(AsyncLoading<List<Item>>(), AsyncData<List<Item>>([])));
  });
}

Output from test:

Listener.call(AsyncLoading<List<Item>>(), AsyncData<List<Item>>(value: []))
package:matcher                        fail
package:mockito/src/mock.dart 797:7    _VerifyCall._checkWith
package:mockito/src/mock.dart 1071:18  _makeVerify.<fn>
test/items_provider_test.dart 25:11    main.<fn>

No matching calls. All calls: Listener.call(AsyncLoading<List<Item>>(), AsyncData<List<Item>>(value: []))
(If you called `verify(...).called(0);`, please instead use `verifyNever(...);`.)

from riverpod.

rrousselGit avatar rrousselGit commented on May 30, 2024

This doesn't throw a noSuchMethodError as you mentioned before though

Your test is failing because [] != []
If you use a const constructor (AsyncData(const [])) in both list creations, that would work.

from riverpod.

rrousselGit avatar rrousselGit commented on May 30, 2024

Closing as this was answered

from riverpod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.