0

I have a 3rd party lib which internally makes a couple of AJAX calls to download remote content. In my test code (jasmine/karma), I get a log that the files were not found (404). The files are not available during testing (they get generated later in the build) so I cannot serve them from karma!

Is there a way to configure karma to serve an empty file with a 200 HTTP status when the request comes in? Or is there a way to mock the AJAX calls in jasmine (NOTE: I do not know exactly how the 3rd party lib is doing the ajax call and I do not want to spend time digging through their code to figure it out).

just.another.programmer
  • 8,579
  • 8
  • 51
  • 90
  • Have you tried using the SinonJs library to create a fake xmlhttprequest object? It's possible to tell it to give a response to requests without knowing what the parameters of that request were. See http://stackoverflow.com/questions/37454372/mocking-xhr-calls-in-jasmine/37470069#37470069. – Andrew Jun 01 '16 at 14:38
  • You can try using `$httpBackend` to fake a call to a service and respond with a file. http://stackoverflow.com/questions/21057477/how-to-return-a-file-content-from-angulars-httpbackend might help you. – SiddAjmera Jun 02 '16 at 12:48
  • @SiddharthAjmera `$httpBackend` only works with the `$http` service. The third party lib is making ajax calls w/out the `$http` service. – just.another.programmer Jun 02 '16 at 16:50

0 Answers0