Skip to content

Instantly share code, notes, and snippets.

@rjmveloso
Last active February 11, 2017 06:49
Show Gist options
  • Save rjmveloso/1a3cd23a36e5ab61cb85e1e3bf0531d4 to your computer and use it in GitHub Desktop.
Save rjmveloso/1a3cd23a36e5ab61cb85e1e3bf0531d4 to your computer and use it in GitHub Desktop.
AngularJS $componentController full locals
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