Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with type mismatch in Query.startAt #296

Open
mario-bermonti opened this issue Mar 9, 2024 · 0 comments
Open

Error with type mismatch in Query.startAt #296

mario-bermonti opened this issue Mar 9, 2024 · 0 comments

Comments

@mario-bermonti
Copy link

I am getting an error when running fake_cloud_firestore in unit tests.

packages versions:
fake_cloud_firestore: ^2.1.0
firebase_core: ^2.8.0
cloud_firestore: ^4.4.5

traceback

Error: The parameter 'values' of the method 'MockQuery.startAt' has type 'List<dynamic>', which does not match the corresponding type, 'Iterable<Object?>', in the overridden method, 'Query.startAt'.
mock_query.dart:125
 - 'List' is from 'dart:core'.
 - 'Iterable' is from 'dart:core'.
 - 'Object' is from 'dart:core'.
Change to a supertype of 'Iterable<Object?>', or, for a covariant parameter, a subtype.
  Query<T> startAt(List<dynamic> values) => _subQueryByKeyValues(

                                 ^
: Context: This is the overridden method ('startAt').
query.dart:138
  Query<T> startAt(Iterable<Object?> values);
           ^

: Error: The parameter 'values' of the method 'MockQuery.endAt' has type 'List<dynamic>', which does not match the corresponding type, 'Iterable<Object?>', in the overridden method, 'Query.endAt'.
mock_query.dart:134
 - 'List' is from 'dart:core'.
 - 'Iterable' is from 'dart:core'.
 - 'Object' is from 'dart:core'.

Change to a supertype of 'Iterable<Object?>', or, for a covariant parameter, a subtype.
  Query<T> endAt(List<dynamic> values) => _subQueryByKeyValues(
                               ^
: Context: This is the overridden method ('endAt').
query.dart:49
  Query<T> endAt(Iterable<Object?> values);
           ^
: Error: The parameter 'arrayContainsAny' of the method 'MockQuery.where' has type 'List<dynamic>?', which does not match the corresponding type, 'Iterable<Object?>?', in the overridden method, 'Query.where'.
mock_query.dart:228
 - 'List' is from 'dart:core'.
 - 'Iterable' is from 'dart:core'.
 - 'Object' is from 'dart:core'.
Change to a supertype of 'Iterable<Object?>?', or, for a covariant parameter, a subtype.
      List<dynamic>? arrayContainsAny,
                     ^
: Context: This is the overridden method ('where').
query.dart:151
  Query<T> where(
           ^

: Error: The parameter 'whereIn' of the method 'MockQuery.where' has type 'List<dynamic>?', which does not match the corresponding type, 'Iterable<Object?>?', in the overridden method, 'Query.where'.
mock_query.dart:229
 - 'List' is from 'dart:core'.
 - 'Iterable' is from 'dart:core'.

 - 'Object' is from 'dart:core'.
Change to a supertype of 'Iterable<Object?>?', or, for a covariant parameter, a subtype.

Code I am testing

  static FirebaseDB init(
    FirebaseFirestore firebaseFirestore, {
    required participantID,
    required sessionID,
    required taskName,
  }) {
    final FirebaseDB db = FirebaseDB(
      firebaseFirestore,
      participantID: participantID,
      sessionID: sessionID,
      taskName: taskName,
    );
    return db;
  }

unit test code

  test('FirebaseDB.init() does not throw an exception', () {
    final FakeFirebaseFirestore fakeFirestore = FakeFirebaseFirestore();

    expect(
        FirebaseDB.init(
          fakeFirestore,
          // FirebaseFirestore.instance,
          participantID: '101',
          sessionID: '001',
          taskName: 'digit_span',
        ),
        returnsNormally);
  });

ChatGPT offered the following solution 😅

Update the Type in Your Test:
Since the error is related to the startAt method, you might need to adjust the arguments you pass when using the startAt method in your test. Ensure that the values passed to startAt are of type Iterable<Object?> instead of List. You can use the Iterable constructor to create an iterable from a list:

Query<T> startAt(List<dynamic> values) => _subQueryByKeyValues(Iterable<Object?>.from(values));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant