In the directive, i'm passing the form Controller and directive controller.
Directive :
App.directive('myDirective', [myDirective]);
function myDirective() {
return {
restrict: 'E',
require: ['myDirective', '^form'],
scope: {
model: '='
},
controller: 'myDirectiveCtrl',
controllerAs: 'ctrl',
template: '`<html></html>`',
link: function(scope, element, attrs, ctrl) {
var directiveCtrl = ctrl[0],formCtrl = ctrl[1];
scope.model.getData = function() {
return directiveCtrl.getData();
};
}
}
jasmine testcase:
it('should provide model data', function() {
var directiveHtml = '`<my-directive model="model"></my-directive>`';
var formHtml = '`<form name="childForm">'+ directiveHtml +
'</form>`';
element = $compile(formHtml)($scope);
controller = element.controller('myDirective');
var scope = element.isolateScope();
$scope.$apply();
['field data1', 'field data2'].forEach(function(data) {
controller.getData = jasmine.createSpy().andReturn(data);
expect(scope.model.getData()).toBe(data);
});
});
I'm using jasmine for testing.i was trying to write spec for
scope.model.getData method.*Controller*and *scope* is coming undefined. Can
anyone tell me what I'm missing?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.