I want to be able to define a variable and then use said variable in the respond() method inside the module.run() function. I have this code inside my it():
var testValue=randomValue(); // suffice to say, a random value generator
var httpBackendMock = function() {
angular.module('httpBackendMock', ['ngMockE2E', 'name.of.app'])
.run(function($httpBackend) {
$httpBackend.whenPOST(/.*\/api\/data/).respond(function(method, url, data, headers) {
return [200, '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> \
<data>'+testValue+'</data>', {}];
});
....
But the testValue variable defined above the httpBackendMock object isn't visible inside the run() function at all, but will be 'undefined'.
My understanding is that 'var' defined variables in JS are available to inner-scoped code, but that's not happening here. Is there some way to get variables to work inside there?
The answer is to pass in a nested array of values and add an argument to the function signature of the mockmodule object.
Found the answer at: Protractor addMockModule additional arguments not working?