javascript - unit testing for input tag with file type -
this directive file input
angular.module("app", []); angular.module("app").directive("filesinput", function () { return { require: "ngmodel", link: function postlink(scope, elem, attrs, ngmodel) { elem.on("change", function (e) { console.log('here'); var files = elem[0].files; ngmodel.$setviewvalue(files); console.log(files[0].size); }) } } }); this html code
<div> <input type="file" files-input ng-model="filearray" multiple> </div> this unit testing. goal mocking actual file or file object triggering change event code inside directive can run. use jasmine. no ui testing in case
describe('unit testing', function () { var $compile, $rootscope; beforeeach(module('app')); beforeeach(inject(function (_$compile_, _$rootscope_) { $compile = _$compile_; $rootscope = _$rootscope_; })); it('test file directive', function () { var element = $compile("<input type='file' files-input ng-model='filearray'>")($rootscope); $rootscope.$digest(); }); }); i not find way mock file object , trigger change event code inside directive can run. using jasmine
Comments
Post a Comment