Is there a way to mock the image that comes from the API using $ httpBackend angularjs?
I am doing protractor tests and using angular moments for "fake" requests. In my application, where is one location where the image should be displayed:
<img ng-src="api/documents/image/{{file.Id}}">
Is it possible to inherit a request to get image data and replace it with some fake image data like it is done with json?
$httpBackend.whenGET('api/documents/123').respond(200,[]);
I am currently getting broken screen image icons which I prefer to replace with some fake images. I hope this is possible ...
respectfully
source to share
ngSrc just takes an expression / static path - it doesn't make a call $http
, which you might mock if your expression is a function call to get images, which is probably not what you want. I would recommend:
1) Add a config variable to the image path that can be toggled for dev / prod, for example:
ng-src="{{ baseUrl }}/api/documents/image/{{file.Id}}"
2) Point this one baseUrl
to the dev server that supplies any mock images you desire. You can create a simple express server that delivers the same image for every request, eg.
source to share