Currently, I am working on implementing an Angular app. During my e2e tests, I encountered a need to mock some server requests while allowing others to pass through using e2e httpBackend.
Vijitta has provided an example of how to utilize the HttpBackend:
` http://jsfiddle.net/vojtajina/DQHdk/ `
However, I face a dilemma where I want my application to boot up with the development module when testing, like so:
<html ng-app="AppDevModule">
On the other hand, during server runs, I prefer the production module to be included:
<html ng-app="AppCoreModule">
Manually switching between these modules in the HTML seems impractical. The documentation for e2e httpBackend offers a snippet for including the development module but does not address this specific issue.
In my setup using angular testacular, I attempted to configure it within the e2e tests as shown below:
describe("DHCP Client e2e.", function () {
beforeEach(function () {
var fakeAppModule = angular.module('AppCoreModule', ['AppCoreModule', 'ngMockE2E']);
fakeAppModule.run(function ($httpBackEnd) {
var networkInterface = [
{
'secondarySubnets':[
{"dhcpOfferOptions":{"dnsServers":["8.8.8.8"], "offerTime":"400", "leaseTime":"600"}, "rangesLimits":[],
"network":"192.168.0.0", "slash":"24", "gateway":"192.168.0.1",
"isDynamic":"dynamic", "description":"asdsadsa"}
]
},
{
'secondarySubnets':[
{"dhcpOfferOptions":{"dnsServers":["8.8.8.8"], "offerTime":"400", "leaseTime":"600"}, "rangesLimits":[],
"network":"192.168.0.0", "slash":"24", "gateway":"192.168.0.1",
"isDynamic":"dynamic", "description":"asdsadsa"}
]
}
];
$httpBackEnd.whenGET('/^\/view\//').respond(200, '<div></div>');
$httpBackEnd.whenGET('/r/networkInterface').respond(200, networkInterface);
$httpBackEnd.whenGET('./../main/webapp/r/networkInterface').respond(200, networkInterface);
});
fakeAppModule.config(function ($provide) {
$provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator);
});
});
Unfortunately, the results did not match my expectations.