App generated by Yeoman with angular-generator.
Directive:
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);
};
}]
};
});
Test:
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();
}));
});
Error:
PhantomJS 1.9.7 (Mac OS X) Directive: scrollTop should have "Back to top"
as text
TypeError: 'undefined' is not a function (evaluating 'element.click()')
I cannot understand where's the problem :( Please post functional code.
Thanks!
Link:
http://stackoverflow.com/questions/25554797/angularjs-how-to-ngclick-an-a-directive-in-a-phantomjs-test
Thanks!
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.