I have an angle instruction that changes the image source of an element if the file does not exist and 404 is returned here This is:
myApp.directive ('fallbacksrc', function) {var fallBackSrc = {link: function postLink} (element, element, attrs) {element.bind ('error', function ( ) {Angular.element (this) .attr ("src", '/images/image-not-available.png');})}}} return decline backscr;}]);
It does the required work but now I am trying to test this instruction to the unit, how will I trigger 'error' that this function is bound in Jasmine?
To test it, you will need to spy on element.bind and use the Jasmines 2.0 function
So in my example, I have added a placeholder image as a replacement image, so that it can cause an error.
angular.module ('components', []). Directive ('Fallbacksrc', function () {var fallBackSrc = {link: function postLink (area, element, attrs) {element.bind ('error', function) (angular.element (this) .attr ("src" 'Http: //placehold.it/350x150');});}} returnbacks backscr;});
And in the test we return to In addition to this, we need to use the work done to run the specs, which it has to do with spyOn
element.bind
and error < Pre>
detective (element, 'bind'). And. Throwanewal ('Error');
setTimeOut
.
Comments
Post a Comment