Please see my code example below, I have a protractor test that get's run as a GULP task by angular-protractor.
I want to be able to mock some REST calls for all it blocks, but also have access to the httpBackend for specific it blocks.
I'm having trouble sharing the $httpBackend variable around though:
- I can't use this.VARIABLE_NAME because of the scope I am in inside the run function.
Code Example
describe('Train Station Search Component', function() {
beforeEach(function() {
//Mock any REST calls here.
browser.addMockModule('httpBackendMock', function() {
angular.module('httpBackendMock', ['MyApp', 'ngMockE2E'])
.run(function($httpBackend) {
//Mock call relevant to both it blocks.
$httpBackend.whenPOST(/^(.*\/api\/search)/).respond({...});
});
});
);
it('should check one piece of functionality', function() {
//Expect call with data relevant only for this it block.
$httpBackend.expectPOST(...);
});
it('should check another piece of functionality', function() {
//Expect call with data relevant only for this it block.
$httpBackend.expectPOST(...);
});
};
Any help appreciated.