I am interested in how to globally shout out the file collector in a browser. In particular, I'm most interested in this in Firefox , but would prefer a general solution.
I don’t care that you don’t see the file selection dialog. I do not need to claim that it opened. The problem is that I have unit tests for JavaScript code that open the file collector. When the dialog opens, it stops the execution of the test suite .
An example of a situation is that I am testing onRender Backbone.View method. This method displays a preview that File Picker will open when it is rendered. Since I did not directly test this view, I would prefer not to mock part of my behavior when I am only interested in unit testing any other part of the onRender method.
Example:
//Test file it("should do something", function() { var view = new App.Views.SomeView(); spyOn(view.modelBinder, "bind"); view.render(); expect(view.modelBinder.bind).toHaveBeenCalled(); }); //View file onRender : function () { this.modelBinder.bind(this.el, this.model); this.$("#thing").html(this.subview.render().el); //This line has a side effect that opens file picker }
In fact, I don’t want to explicitly state the behavior that causes the file collector to open, because I'm not interested in testing here. This will make the test suite much more fragile and difficult to maintain.
source share