I am interested in testing my angular application using protractor. The app includes an API Module that communicates with the server In these tests, I would like to mock this API Module. I am not looking to perform full integration tests, but rather tests based on user input with expected values from the API. This approach could potentially speed up client tests and allow for testing of edge cases, such as connection errors.
How can I achieve this with protractor? I am just beginning to set up integration tests.
I have utilized the npm protractor module, installed selenium, modified the default configuration, and utilized the onProtractorRunner.js to confirm my setup is functioning correctly.
What is the recommended method of mocking? My understanding is that mocking should be performed within the browser rather than directly in the test file. Since the commands in the test file are protractor-specific and sent to the selenium runners, I am unable to share JavaScript objects during the session and the test.
I anticipate that I may need to use a spy library such as sinon.js or if this functionality is already included in protractor.
Edit: I have come across this issue in the protractor issue tracker, which could potentially be a solution. Essentially, you would create a Mock Module in the test, which is then executed in the browser or the application's scope.
Edit: I have found some other promising issues. The first one discusses adding Mocks to the Angular App. The second addresses the topic of mocking the backend.
This approach seems very promising, as it would allow the Angular App to remain in its original state. However, it currently only works with the deprecated ng-scenarios.