describe('Directive http-click', () => { let $scope; let element; let compile; beforeEach(ngModule('vnCore')); compile = (_element, _childElement) => { inject(($compile, $rootScope) => { $scope = $rootScope.$new(); element = angular.element(_element); $compile(element)($scope); $scope.$digest(); }); }; it('should call click function on the element, disable it and then enable it again', () => { let html = ``; compile(html); const myPromise = new Promise(resolve => resolve()); $scope.myEvent = () => { return myPromise; }; element[0].$ctrl = {disabled: false}; element[0].click(); expect(element[0].$ctrl.disabled).toEqual(true); let finalValue; myPromise.then(() => { finalValue = 'called!'; expect(element[0].$ctrl.disabled).toEqual(false); }).finally(() => { expect(finalValue).toEqual('called!'); }); }); it('should call click function on the element and not disable it', () => { let html = ``; compile(html); const myPromise = new Promise(resolve => resolve()); $scope.myEvent = () => { return myPromise; }; element[0].$ctrl = {disabled: true}; element[0].click(); expect(element[0].$ctrl.disabled).toEqual(true); let finalValue; myPromise.then(() => { finalValue = 'called!'; expect(element[0].$ctrl.disabled).toEqual(true); }).finally(() => { expect(finalValue).toEqual('called!'); }).catch(err => { throw err; }); }); });