Manya
Manya

Reputation: 315

Protractor addMockModule for angular applications without ngApp

The angular application on which I am running my e2e tests does not have ngApp directive and bootstraps manually. Is it not possible to insert mock modules via Protractor in this case?

//load angular mocks as a string here    
var angularMocks = require('./angularMocks.module.js').mock;
            browser.addMockModule("ngMockE2E", angularMocks );
            browser.addMockModule('httpBackendMock', function httpBackendMock() {
                console.log('inside httpBackendMock');
                angular.module("httpBackendMock", ['ngMockE2E'])
                    .run(['$httpBackend', function ($httpBackend) {
                        console.log("Inside Run");
                        $httpBackend.whenGET(/.*employees.*/).respond(404, '');

                        $httpBackend.whenGET(/.*/).passThrough();
                        $httpBackend.whenPOST(/.*/).passThrough();
                        $httpBackend.whenPUT(/.*/).passThrough();
                                       }]);
            });
            browser.get(url);

This logs 'inside httpBackendMock' in the browser console but not 'Inside Run' indicating that the API calls are never intercepted.

Upvotes: 0

Views: 497

Answers (0)

Related Questions