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


source to share





All Articles