Como clicar com o botão direito do mouse em uma diretiva A em um teste do PhantomJS
App gerado pela Yeoman com gerador angular.
Directiva:
angular.module('psApp').directive('scrollTop', function () {
return {
restrict: 'A',
scope: true,
template: '<a href="#" ng-click="click()" class="scroll-top"><span class="glyphicon glyphicon-arrow-up"></span> Back to top</a>',
controller: ['$scope', '$element', '$document', function ($scope, $element, $document) {
$scope.click = function () {
$document.scrollTop(0, 500);
};
}]
};
});
Teste:
describe('Directive: scrollTop', function () {
// load the directive's module
beforeEach(module('psApp'));
var scope, element;
beforeEach(inject(function ($rootScope, $compile) {
scope = $rootScope.$new();
element = $compile('<div scroll-top></div>')(scope);
scope.$apply();
}));
it('should have "Back to top" as text', inject(function () {
expect(element.html()).toBe('<a href="#" ng-click="click()" class="scroll-top"><span class="glyphicon glyphicon-arrow-up"></span> Back to top</a>');
expect(element.text()).toBe(' Back to top');
element.click();
}));
});
Erro:
Diretiva PhantomJS 1.9.7 (Mac OS X): o scrollTop deve ter "Voltar ao topo" como texto TypeError: 'undefined' não é uma função (avaliar 'element.click ()')
Não consigo entender onde está o problema. :( Por favor, poste código funcional.