Komponententests: Speichern Gerät Feuerbasis Token

stimmen
0

Ich versuche, diese Methode zu testen, das eine Gerät speichert Token Firestor.

save_token.dart

class Notification {
  void saveDeviceToken() async {
    FirebaseUser user = await firebaseAuth.currentUser();
    await fcm.getToken().then((token) {
      db.collection('users').document(user.email).setData({
        'device_token': token,
        'createdAt': FieldValue.serverTimestamp(),
      });
    });
  }
}

Hier ist , was ich versucht habe bisher: save_token_test.dart

test('should save device token', () {
final Notification notification = Notification();
final firebaseAuth = FirebaseAuth();

      when(firebaseAuth.currentUser())
          .thenAnswer((_) => Future<FirebaseUser>.value(firebaseUser));
      when(firebaseMessaging.getToken())
          .thenAnswer((_) => Future<dynamic>.value('SOMETOKEN'));
      when(firestore.collection('users').document(any).setData(any))
          .thenAnswer((realInvocation) => null);
      notification.saveDeviceToken();
    });

Aber ich bin immer diesen Fehler

00:02 +1 -1: Notification Setup should save device token [E]                                            
  NoSuchMethodError: The method 'document' was called on null.
  Receiver: null
  Tried calling: document(null)
  dart:core                                                     Object.noSuchMethod
  tests/unit_tests/shared/widgets/notification_test.dart 64:42  main.<fn>.<fn>

Was sind die Ursachen dieser Fehler und wie kann ich sie lösen?

Veröffentlicht am 14/02/2020 um 00:04
quelle vom benutzer
In anderen Sprachen...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more