title: Test Ionic + Anguar app Platform.backButton undefined error when calling subscribeWithPriority()
body: <p>I'm setting up a basic test suit for my very small Ionic + Angular app.</p>
  <p>In my <code>app.component.ts</code> I subscribe to the <code>backButton</code> event:</p>
  <pre class="lang-js prettyprint-override"><code>this.platform.backButton.subscribeWithPriority(10, () =&gt; {
    // some code
  }); 
  </code></pre>
  <p>and when I run <code>ng test</code> I get the error:</p>
  <blockquote>
  <p>TypeError: Cannot read property ‘subscribeWithPriority’ of undefined</p>
  </blockquote>
  <p>meaning that backButton is not defined in the test. So, I added backButton this way:</p>
  <pre class="lang-js prettyprint-override"><code>platformSpy = jasmine.createSpyObj('Platform', {
    ready: platformReadySpy,
    backButton: mockBackButton,  // a mock function
  });
  </code></pre>
  <p>but the test is still complaining that <code>backButton</code> is not a function.</p>
  <p>Is there a way to mock <code>Platform</code> and <code>backButton</code> to solve this issues?</p>
  <p>These are the two files related to the issue:</p>
  <p><code>app.component.ts:</code></p>
  <pre class="lang-js prettyprint-override"><code>import { Component, ViewChild } from '@angular/core';
  
  import { Platform, IonRouterOutlet, AlertController } from '@ionic/angular';
  import { SplashScreen } from '@ionic-native/splash-screen/ngx';
  import { StatusBar } from '@ionic-native/status-bar/ngx';
  
  import { Location } from '@angular/common';
  import { Plugins } from '@capacitor/core';
  const { App } = Plugins;
  
  @Component({
    selector: 'app-root',
    templateUrl: 'app.component.html',
    styleUrls: ['app.component.scss']
  })
  
  export class AppComponent {
    @ViewChild(IonRouterOutlet, {static: true}) routerOutlet: IonRouterOutlet;
    constructor(
      private platform: Platform,
      private splashScreen: SplashScreen,
      private statusBar: StatusBar,
      private location: Location,
      private alertController: AlertController
    ) {
      this.initializeApp();
      this.backButtonEvent();
    }
  
    initializeApp() {
      this.platform.ready().then(() =&gt; {
        this.statusBar.styleDefault();
        this.splashScreen.hide();
      });
    }
  
    backButtonEvent() {
      this.platform.backButton.subscribeWithPriority(10, () =&gt; {
        if (!this.routerOutlet.canGoBack()) {
          this.backButtonAlert();
        } else {
          this.location.back();
        }
      });
    }
  
    async backButtonAlert() {
      // code for showing alert...
    }
  }
  </code></pre>
  <p><code>app.component.spec.ts:</code></p>
  <pre class="lang-js prettyprint-override"><code>import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
  import { TestBed, async } from '@angular/core/testing';
  
  import { Platform } from '@ionic/angular';
  import { SplashScreen } from '@ionic-native/splash-screen/ngx';
  import { StatusBar } from '@ionic-native/status-bar/ngx';
  
  import { AppComponent } from './app.component';
  
  describe('AppComponent', () =&gt; {
  
    let statusBarSpy;
    let splashScreenSpy;
    let platformReadySpy;
    let platformSpy;
  
    beforeEach(async(() =&gt; {
      statusBarSpy = jasmine.createSpyObj('StatusBar', ['styleDefault']);
      splashScreenSpy = jasmine.createSpyObj('SplashScreen', ['hide']);
      platformReadySpy = Promise.resolve();
      platformSpy = jasmine.createSpyObj('Platform', { ready: platformReadySpy });
  
      TestBed.configureTestingModule({
        declarations: [AppComponent],
        schemas: [CUSTOM_ELEMENTS_SCHEMA],
        providers: [
          { provide: StatusBar, useValue: statusBarSpy },
          { provide: SplashScreen, useValue: splashScreenSpy },
          { provide: Platform, useValue: platformSpy },
        ],
      }).compileComponents();
    }));
  
    it('should create the app', () =&gt; {
      const fixture = TestBed.createComponent(AppComponent);
      const app = fixture.debugElement.componentInstance;
      expect(app).toBeTruthy();
    });
  
    it('should initialize the app', async () =&gt; {
      TestBed.createComponent(AppComponent);
      expect(platformSpy.ready).toHaveBeenCalled();
      await platformReadySpy;
      expect(statusBarSpy.styleDefault).toHaveBeenCalled();
      expect(splashScreenSpy.hide).toHaveBeenCalled();
    });
  
    // ... more tests
  
  });
  </code></pre>
  <p>Software versions:
  Ionic (6.12.3) + Angular (10.0.14)</p>