All,
I have a unit test suite for a AngularJS controller that follows the pattern beforeEach()
:
var ResourcesCtrl,
scope, rootScope, loc, ctrl;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $location) {
scope = {};
rootScope = {};
loc = $location;
ctrl = $controller;
scope.instanceName = 'TestInstance';
ResourcesCtrl = $controller('ResourcesCtrl', {
$scope: scope,
$rootScope: rootScope,
$location: loc
});
}));
Then a bunch of it()
blocks with assertions/expect that all work as expected.
Now what I need to do, in just one of the test cases I'm adding, is change the value of scope.instanceName
; however, it appears that even if I change its value inside the it()
test case, that's not reflected in the scope of the controller. I have tried instantiating the controller with a new scope inside the test case, but that hasn't worked either.
So my question is the following: how can I change/override variables that were passed to the controller in the beforeEach()
setup?