Exploring AngularJS Protractor End-to-End Mocking

In my Angular SPA, I am retrieving data from a node backend that is fully covered with tests. To mock the Angular HTTP calls, I want to implement something like this:

Api = $injector.get('Api');
sinon.mock(Api, 'getSomethingFromServer').andRespondWith({foo: 'bar'})
assert(Api.getSomethingFromServer.wasCalledOnce);

Despite searching for a solution, I have not been able to find a satisfactory one. Various posts address the same issue, such as this one.

Given that protractor undergoes frequent changes, I am turning to SO in hopes of finding anyone who has found a proper solution for mocking HTTP requests.

Answer №1

Currently, we are utilizing for this purpose.
In addition to being able to simulate responses, you also receive a comprehensive API description as an added benefit! Our process involves running the Angular application through a proxy, which enables us to route requests either to the actual backend or the one supplied by apiary based on whether we are in development or production.

Answer №2

I concur with the earlier response. A solution to the issue of Protractor constantly changing is to completely detach the backend from the system being tested, whether it's through mocking, stubbing, or using a fake backend.

The challenge lies in ensuring that there remains a solid alignment with the actual backend, but it may not necessarily be more burdensome than continuously adjusting mock setups within Angular.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

PHP-generated AngularJs Select Element

I'm facing an issue with my PHP function in my AngularJS application. I have created a function to select a default option, but it's not displaying the desired value. Here is the function code: function qtyList($selectName, $selectQty){ $st ...

Using AngularJS service to perform a GET request

I'm just starting to learn about angularJS and I'm trying to understand how to make a GET request to an external server. The documentation provides an example request like this: Example Request curl -H 'Accept: application/vnd.twitchtv.v ...

Resolve functionality in UI Router fails to function properly when utilizing component-based states

Issue: In a project I am currently involved in, there is a component that is utilized in two different scenarios. One instance involves calling it from the Material Design system's bottomSheet, while the other requires direct usage through the ui-ro ...

Confused about having to use window.variableName in my code and not understanding the reason

Working on a web app with JS, Angular, and Meteor that integrates the Youtube API has been quite challenging. In one of my controllers, I initialized the youtube player object in the constructor following the necessary steps outlined by the Youtube API. Ho ...

ng-table Filtering with dropdown selection

Hello, I am currently working on creating a Ng-table with a select dropdown menu for filtering the results. Here is where I am at so far. 1) How can I remove one of the pagination options that appear after applying the filter? I only want to keep one pagi ...

AngularJS and ui-grid are a dynamic duo in web development

Could anyone provide guidance on removing the excess white space following rows in a grid? I am looking to have it perfectly align with the number of rows and remain sticky. No white space required in that area. ...

I am experiencing difficulty selecting a precise geolocation using a Postgres query

I'm currently working on an API and encountering a frustrating issue. Whenever I execute the following query: SELECT * FROM u.loc It retrieves all user locations along with additional data, including a parameter called "geocode": ex. "geocode":"(48 ...

Attempting to locate an element within the DOM using TypeScript

I am completely new to TypeScript. I have been attempting to locate an element using a selector, but no matter what I tried, the findElement() method always returns undefined. Can someone please point out where my mistake might be? Any assistance would b ...

Error message: Element not found while running onPrepare in protractor.conf.js

I am currently in the process of writing end-to-end tests for an AngularJS application using Jasmine and protractor. I have encountered an issue with the onPrepare function in the protractor.conf.js. When I perform the following actions within a beforeAl ...

The jsonp typeahead feature is not populating the uib-typeahead form element

Trying to populate a uib-typeahead from the ui-bootstrap modules using a jsonp callback function in a factory method has been challenging. This is the factory function being used: autoCompleteCity: function(city){ return $http.jsonp("http://g ...

Can you explain the significance of the output "Object[...]" displayed in Firebug?

Currently, I am logging an object within an AngularJS directive. Specifically, I am focusing on the parameters of the link() function of the directive. Here is the code snippet: link: function(scope, element, attrs) { console.log(attrs) } Upon checking ...

Utilizing AngularJS to iterate through an array of dictionaries

Within a specific section of my HTML code, I am initializing a scope variable like this: $scope.my_data = [ { c1: "r1c1", c2: "r1c2", c3: "r1c3", ...

Tips for creating a row template with pinned content

When setting pinning and rowTemplate together, the rowTemplate repeats 3 times in a single row. I suspect it is related to the pinning column, but I am unsure how to rectify it. Here's the link to the Plunker showcasing the issue: http://plnkr.co/ed ...

What is the best way to handle multiple promises when loading a state in Angular?

When loading the /home state, I need to retrieve all users from the database in order to customize the home controller and view based on the logged-in user. Currently, in the :resolve section of the state configuration, I am fetching all 'posts' ...

Guide to automating tests on MAC using Protractor with Appium and IOS-Simulator

Is there a way to run automated tests using Protractor (or WebDriverJS) on a MAC with Appium and the IOS Simulator? We have been unsuccessful in running tests with the following configuration file, although it works fine with Selenium 2.0 - WebDriver. He ...

Error: The database query returned duplicate results while using ngRepeat

I have encountered a persistent error that seems to be related to the "fetchCourses()" function in courses.js. Despite various attempts, the error persists and only goes away when I comment out this particular function. My suspicion is on the HTTP request, ...

The issue of AngularJS $http.get not functioning properly with a jsp page has arisen due to its simplicity

1 / I developed a myPage.jsp page within an eclipse project named erixx : <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE> <html><head></head> <body> <% String aa ...

Issue with setting multiple checkboxes in AG Grid

I have a situation where I am trying to select multiple checkboxes on different rows in my application. Each time I click on one checkbox, it gets selected just fine. However, when I click on another checkbox in a different row, the previously selected che ...

Transmit a sequence of keys to the web browser

I'm having difficulty in sending a Shift key command followed immediately by tilde (~). I've attempted various examples, and here's one that I'm currently working on. I am testing the following scenario - selecting a specific image, t ...

Is it possible to develop an AngularJS application using a basic ASPX framework?

Is it possible to develop an Angular Js application within ASPX web forms while following a three tier architecture approach, including separate layers for the database and business logic? ...