Mock ionic/native firebase plugin


#1

I used firebase plugin for push notifications I want to write the test cases for that I need to mock Firebase: ‘@ionic-native/firebase/ngx’; how to mock this?

I tried to mock firebase using FirebaseMock: '@ionic-native-mocks/firebase but while running ng test it is throwing ERROR in node_modules/@ionic-native-mocks/firebase/index.d.ts(3,43): error TS2507: Type ‘FirebaseOriginal’ is not a constructor function type


#2

I have not updated the Ionic Native Mocks to the latest version yet (soon!). That is probably the source of the error.


#3

fire base mock:

import { Firebase } from ‘@ionic-native/firebase/ngx’;
import { Observable } from ‘rxjs/Observable’;
import { Observer } from ‘rxjs/Observer’;
import { MenuControllerMock } from ‘ionic-mocks’;

export class FirebaseMock extends Firebase {
/**
* Get the device token
* @return {Promise}
/
getToken(): Promise {
return new Promise((resolve, reject) => {
resolve();
});
};
/
*
* Get notified when a token is refreshed
* @return {Observable}
/
onTokenRefresh(): Observable {
return Observable.create((observer: Observer) => {
observer.next(’’);
observer.complete();
});
};
/
*
* Get notified when the user opens a notification
* @return {Observable}
/
onNotificationOpen(): Observable {
return Observable.create((observer: Observer) => {
observer.next(’’);
observer.complete();
});
};
/
*
* Grant permission to receive push notifications
* @return {Promise}
/
grantPermission(): Promise {
return new Promise((resolve, reject) => {
resolve();
});
};
/
*

  • Check permission to receive push notifications
  • @return {Promise}
    /
    hasPermission(): Promise {
    return new Promise((resolve, reject) => {
    resolve();
    });
    };
    /
    *
    • Set icon badge number. Set to 0 to clear the badge.
    • @param badgeNumber {number}
    • @return {Promise}
      /
      setBadgeNumber(badgeNumber: number): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Get icon badge number
    • @return {Promise}
      /
      getBadgeNumber(): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Subscribe to a topic
    • @param topic {string}
    • @return {Promise}
      /
      subscribe(topic: string): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Unsubscribe from a topic
    • @param topic {string}
    • @return {Promise}
      /
      unsubscribe(topic: string): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Log an event using Analytics
    • @param type {string}
    • @param data {Object}
    • @return {Promise}
      /
      logEvent(type: string, data: any): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Log an Error using FirebaseCrash
    • @param message {string}
    • @return {Promise}
      /
      logError(message: string): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Set the name of the current screen in Analytics
    • @param name {string} Screen name
    • @return {Promise}
      /
      setScreenName(name: string): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Set a user id for use in Analytics
    • @param userId {string}
    • @return {Promise}
      /
      setUserId(userId: string): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Set a user property for use in Analytics
    • @param name {string}
    • @param value {string}
    • @return {Promise}
      /
      setUserProperty(name: string, value: string): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Fetch Remote Config parameter values for your app
    • @param cacheExpirationSeconds
    • @return {Promise}
      /
      fetch(cacheExpirationSeconds?: number): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Activate the Remote Config fetched config
    • @return {Promise}
      /
      activateFetched(): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Retrieve a Remote Config value
    • @param key {string}
    • @param namespace {string}
    • @return {Promise}
      /
      getValue(key: string, namespace?: string): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Retrieve a Remote Config byte array
    • @param key {string}
    • @param namespace {string}
    • @return {Promise}
      /
      getByteArray(key: string, namespace?: string): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Get the current state of the FirebaseRemoteConfig singleton object
    • @return {Promise}
      /
      getInfo(): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Change the settings for the FirebaseRemoteConfig object’s operations
    • @param settings {Object}
    • @return {Promise}
      /
      setConfigSettings(settings: any): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      /
      *
    • Set defaults in the Remote Config
    • @param defaults {Object}
    • @param namespace {string}
    • @return {Promise}
      */
      setDefaults(defaults: any, namespace: string): Promise {
      return new Promise((resolve, reject) => {
      resolve();
      });
      };
      }