'use strict'; /* eslint-disable no-script-url */ describe('ngSrcset', function() { var element; afterEach(function() { dealoc(element); }); it('should not result empty string in img srcset', inject(function($rootScope, $compile) { $rootScope.image = {}; element = $compile('')($rootScope); $rootScope.$digest(); expect(element.attr('srcset')).toBeUndefined(); })); it('should sanitize good urls', inject(function($rootScope, $compile) { $rootScope.imageUrl = 'http://example.com/image1.png 1x, http://example.com/image2.png 2x'; element = $compile('')($rootScope); $rootScope.$digest(); expect(element.attr('srcset')).toBe('http://example.com/image1.png 1x,http://example.com/image2.png 2x'); })); it('should sanitize evil url', inject(function($rootScope, $compile) { $rootScope.imageUrl = 'http://example.com/image1.png 1x, javascript:doEvilStuff() 2x'; element = $compile('')($rootScope); $rootScope.$digest(); expect(element.attr('srcset')).toBe('http://example.com/image1.png 1x,unsafe:javascript:doEvilStuff() 2x'); })); it('should not throw an error if undefined', inject(function($rootScope, $compile) { element = $compile('')($rootScope); $rootScope.$digest(); })); it('should interpolate the expression and bind to srcset', inject(function($compile, $rootScope) { var element = $compile('')($rootScope); $rootScope.$digest(); expect(element.attr('srcset')).toBeUndefined(); $rootScope.$apply(function() { $rootScope.id = 1; }); expect(element.attr('srcset')).toEqual('some/1 2x'); dealoc(element); })); });