title: Unit testing cordova 'deviceready' event in angular application
body: <p>Unit testing cordova 'deviceready' event in angular application - I am using cordova to convert my angular 5 application to mobile app and I am able to do that. I am getting app version and build number details via cordova plugin once the deviceready event fired from cordova. I would like to test this scenario in unit testing. I have a route guard service in my app which will determine to allow user to login or redirect to different page based on the version. so in my guard I have the below code.</p>
  
  <p>canActivate(): Observable | Promise | boolean {</p>
  
  <pre><code>if (this.utils.isMobile()) {
    return new Observable((observer) =&gt; {
      this.utils.getSomeData().subscribe((d) =&gt; {
        document.addEventListener('deviceready', () =&gt; {
          if (this.utils.compareData('5', '55')) {
            observer.next(true);
            observer.complete();
          } else {
            observer.next(false);
            observer.complete();
          }
        });
      });
    });
  }
  
  return true;
  </code></pre>
  
  <p>}</p>
  
  <p>I had to use custom observer here in order to make my canActivate wait till the device ready event fire and comparison have completed. I am facing difficulties testing this. How do I fire this event and test the observer at the same time?</p>