angularjs - Instantiating a controller that uses an isolate scope for a test -
so have controller test file with:
scope = $rootscope.$new(); ctrlinstance = $controller( 'formctrl', { $scope: scope } );
this controller isn't getting instantiated correctly, because scope i'm passing in doesn't have data has (due being passed isolate scope).
these first few lines of formctrl:
var vm = this; vm.stats = angular.copy( vm.statsstuff ); vm.stats.showx = vm.stats.showy = true;
note vm.statsstuff has data bound (due '=' scope in corresponding directive), i'm not sure how pass these values when instantiate controller in test.
any appreciated.
adding directive:
angular.module( 'mymodule' ) .directive( 'formstuff', function() { return { restrict: 'e', templateurl: 'dir.tpl.html', scope: { statsstuff: '=' }, controller: 'formstuffctrl', controlleras: 'formctrl', bindtocontroller: true }; } ); })();
the angular-mocks module has $controller service decorates "real" one, , allows passing third argument, containing data bind controller before instantiating it.
so should need is
ctrlinstance = $controller('formctrl', { $scope: scope }, { statsstuff: thestuff } );
Comments
Post a Comment