How to provide mock files to change event of <input type='file'> for unit testing

前端 未结 4 427
死守一世寂寞
死守一世寂寞 2021-01-03 21:21

I\'m having difficulties with a unit test in which I want to verify the processing of a file, which would usually be selected in the view via

4条回答
  •  时光取名叫无心
    2021-01-03 21:33

    Your file change handler should probably be a function directly on your controller. You can bind that function to the change event either from the HTML or a directive. That way you can call your handler function directly without worrying about triggering an event. This egghead.io video covers a couple ways you can do that: https://egghead.io/lessons/angularjs-file-uploads

    There are a lot of things you need to worry about when rolling your own file uploader with Angular so I would just use one of the existing libraries out there that takes care of it. e.g. angular-file-upload

提交回复
热议问题