Injecting variables when mocking module
Hey guys,
Here is the example:
var mockedModule=function(){
var module = angular.module('example-module').config(['$provide',function($provide){
$provide.constant('someConstant','value');
}])
}
browser.addMockModule('example-module',mockedModule);
So in the tests i want to assert agans the constant's value right? Well even if i write a normal spec i must write it as a 'value'. This is duplication of course. What if i have more complicated variables, objects, services and etc.
I couldn't found way to inject shared variable when mocking module.
Refactored example:
var value = 'value'
var mockedModule=function(){
var module = angular.module('example-module').config(['$provide',function($provide){
$provide.constant('someConstant',value);
}])
}
and asserting will be against the value variable itself, not the value of the variable. Duplication removed.
Maybe i'm missing something... So thank you.
No, you're not missing something - the code that is run in the mockedModule is run in a separate context from the test. One is in the browser, one is in the node.js process running the test. So, you'll need a little duplication here. I'd say that's OK for tests.
@juliemr Thank you very much for the answer. This clarifies a lot. :) :+1: