title: Mock Angular HttpClient in protractor e2e test
body: <p>My application is making an http call to my backend immediately on page load. My e2e test is failing because there is no backend running in my ci pipelines.</p>
  <p>I have tried using the rxjs catchError piped operator on the http call</p>
  <p>I have tried wrapping the whole http call in a try / except block</p>
  <p>I am still getting the error showing up in the dev console (which is causing the e2e test to fail)</p>
  <p>I am wondering how I can provide a mock <code>HttpClient</code> to the protractor tests?</p>
  <p>Actual Http call</p>
  <p><code>return this.http.get&lt;any&gt;( url ).subscribe(...)</code></p>
  <p>(<code>this.http</code> is an instance of angular's <code>HttpClient</code>)</p>
  <p>spec file:</p>
  <pre><code>import { AppPage } from './app.po';
  import { browser, logging } from 'protractor';
  
  describe( 'workspace-project App', () =&gt; {
    let page: AppPage;
  
    beforeEach( () =&gt; {
      page = new AppPage();
    } );
  
    it( 'should display login page', () =&gt; {
      page.navigateTo();
      expect( page.getLoginTitleText() ).toEqual( 'Welcome to\nApp\nClick below to sign in with Google' );
    } );
  
    afterEach( async () =&gt; {
      // Assert that there are no errors emitted from the browser
      const logs = await browser.manage().logs().get( logging.Type.BROWSER );
      expect( logs ).not.toContain( jasmine.objectContaining( {
        level: logging.Level.SEVERE,
      } as logging.Entry ) );
    } );
  } );
  </code></pre>
  <p>protractor's page object file (<code>app.po</code>)</p>
  <pre><code>import { browser, by, element } from 'protractor';
  
  export class AppPage {
    public navigateTo() {
      return browser.get( browser.baseUrl ) as Promise&lt;any&gt;;
    }
  
    public getLoginTitleText() {
      return element( by.css( 'app-root app-login div.login-wrapper form.login section.title' ) )
        .getText() as Promise&lt;string&gt;;
    }
  }
  </code></pre>
  <p>error in dev console:
  <a href="https://i.stack.imgur.com/lpWwf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lpWwf.png" alt="enter image description here" /></a></p>