How to use Sinon in mocha to mock input type = "file" for AJAX testing

I got a unit test on Mocha and I am testing a form via AJAX.

Since you can't manually fill in <input type="file">

, and I'm looking for automated tests, I need to know what is the best way to "mock" this input and still be able to send it via AJAX in multipart format (could be a regular text "file", for example with Hello world!).

I know I can just create the string manually, but I need to "replace" the value <input type="file">

in the object with my mock (which can still react to my mocked object FormData

)

+3
html5 unit-testing file-upload mocha sinon


source to share


No one has answered this question yet

Check out similar questions:

2560
How can I test a private function or class with private methods, fields or inner classes?
857
How to mock empty methods with Mockito
694
JQuery Ajax file upload
536
Is there a float input type in HTML5?
390
How to increase timeout for one test case in mocha
131
How can I mock importing an ES6 module?
6
How can I test a method in a controller in sails.js using Mocha + Sinon?
4
How to defrost a mocha?
3
Reading in file (image) for Mocha / React Unit Test
2
Testing a binary file upload with mocha



All Articles
Loading...
X
Show
Funny
Dev
Pics