Last active
February 11, 2017 06:49
-
-
Save rjmveloso/1a3cd23a36e5ab61cb85e1e3bf0531d4 to your computer and use it in GitHub Desktop.
AngularJS $componentController full locals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('angular-component-controller', function() { | |
// save injected parameters of controller | |
var injected = {}; | |
var controller; | |
// @see $https://docs.angularjs.org/api/ngMock/service/$componentController | |
// we need to extract those from $compile instead of use as locals | |
angular.module('locals', []).controller('controller', | |
['$attrs', function($attrs) { | |
// save $attrs to make use of $observe | |
injected.$attrs = $attrs; | |
}] | |
); | |
beforeEach(module('locals')); | |
beforeEach(inject(function($rootScope, $compile, $componentController) { | |
// invoke dummy controller to get $attrs | |
$compile('<span ng-controller="controller">')($rootScope); | |
var locals = {}; | |
locals.$scope = $rootScope.$new(); | |
locals.$attrs = injected.$attrs; | |
var bindings = {}; | |
controller = $componentController('component', locals, bindings); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment