describe('Directive zoomImage', () => { let compile; let scope; let srcDefault = 'http://default.img.jpg/'; let srcZoom = 'http://zoom.img.jpg/'; let findContainer; beforeEach(ngModule('vnCore')); beforeEach(inject(($compile, $rootScope) => { compile = $compile; scope = $rootScope.$new(); })); afterEach(() => { if (findContainer) { findContainer.parentNode.removeChild(findContainer); findContainer = undefined; } }); function getCompiledImage(imgHtml) { let element = angular.element(imgHtml); let compiledElement = compile(element)(scope); scope.$digest(); return compiledElement; } it('should create zoom container when click into image', () => { let image = getCompiledImage(``); image[0].click(); findContainer = document.querySelector('.vn-zoom-image'); expect(findContainer).not.toBeNull(); }); it('should detroy zoom container when click outside zoomed image', () => { let image = getCompiledImage(``); image[0].click(); findContainer = document.querySelector('.vn-zoom-image'); findContainer.click(); findContainer = document.querySelector('.vn-zoom-image'); expect(findContainer).toBeNull(); }); it('should create new image, into zoom container, with src as original image src', () => { let image = getCompiledImage(``); image[0].click(); findContainer = document.querySelector('.vn-zoom-image'); let zoomedImg = findContainer.querySelector('img'); expect(zoomedImg.src).toEqual(srcDefault); }); it('should create new image, into zoom container, with src likes zoomImage value', () => { let image = getCompiledImage(``); image[0].click(); findContainer = document.querySelector('.vn-zoom-image'); let zoomedImg = findContainer.querySelector('img'); expect(zoomedImg.src).toEqual(srcZoom); }); });