javascript - How do I properly initialize/mock and unit test input data in a directive's externally-defined controller? -
i have custom directive uses external controller , template. user passes in initial data directive, used inside controller.
when i'm unit testing mycontroller, this.inputdata undefined. how initialize or mock this.inputdata in unit test can test mycustomfilter called defined value in first parameter?
customdirective:
'use strict'; angular.module('mymodule') .directive('mydirectve', function () { return { restrict: 'ea', scope: { inputdata: '=' }, templateurl: 'templates/my-directive-template.html', bindtocontroller: true, controlleras: 'main', controller: 'mymainctrl', link: function () { } }; });
directivecontroller:
'use strict'; angular.module('mymodule') .controller('mymainctrl', function (mycustomfilter) { this.filtereddata = mycustomfilter(this.inputdata, true); });
my-directive-template:
<span>{{ main.filtereddata.length }}</span>
using mydirective:
<my-directive inputdata="myinputdata"></my-directive>
Comments
Post a Comment