title: Mocking and Stubbing with protractor
body: <p>I want to test my angular app with protractor.
  The app has an API Module that talks to the server
  During these tests I want to mock this Api Module.
  I don't want to do full integration tests, but tests from the user input with expected values from the API.
  Not only could this make the client tests faster, it would also allow me to test for edge cases, like connection errors.</p>
  
  <p>How can I do this with protractor?
  I just started to setup integration tests.</p>
  
  <p>I used the npm protractor module, installed selenium, adjusted the default config and used the <a href="https://github.com/angular/protractor/blob/master/example/onProtractorRunner.js">onProtractorRunner.js</a> to verify my setup works.</p>
  
  <p>What is the recommended way of mocking?
  I assume that the mocking has to be done within the browser and not directly in the test file.
  I assume that the commands in the test file are protractor specific and will be sent to the selenium runners. Therefore I can't share javascript objects during the session and the test.</p>
  
  <p>I somehow expect that I will need a spy library like <a href="http://sinonjs.org/">sinon.js</a> or is this already included in protractor?</p>
  
  <p><strong>Edit:</strong> I read about <a href="https://github.com/angular/protractor/issues/31">this issue in the protractor issue tracker</a>, which could be a way to do it.
  Basically you write a Mock Module in the test, that is sent to be executed in the browser/ the applications scope.</p>
  
  <p><strong>Edit:</strong> Here are more promising Issues. The first talks about <a href="https://github.com/angular/protractor/issues/110">adding Mocks to the Angular App</a>.
  The second talks about <a href="https://github.com/angular/protractor/issues/69">mocking the backend</a>.</p>
  
  <p>This looks really nice, in this case the Angular App would stay in it's original form. However this currently only works with the deprecated ng-scenarios.</p>