I try to setup my independent protractor project to mock some of my backend requests. Therefore, I included angular-mocks.js
and attached another module within the onPrepare()
function of my protractor.conf.js:
browser.addMockModule('httpBackend', function() {
angular.module('httpBackend', ['myApp', 'ngMockE2E']).run(function($httpBackend) {
$httpBackend.whenPOST(/^requests\/*/).respond(function(method, url, data) {
var obj = {"msg": "Response!"};
return [200, JSON.stringify(obj), {}];
});
})
})
This lets me intercept any request but I am not getting what I want to return in respond()
. It seems I am just getting a 200 OK
.
What am I doing wrong?
Just to let you know how I solved it:
The docs say the following:
In my case, the headers Object somehow does not seem to be optional and I ended with setting it on my own before returning the array:
Anybody has a clue why this is necessary or which of its attributes is obsolete?