如何测试AngularJS指令
我正在使用一个将使用AngularJS的Rails 3.2应用程序。我可以得到Angular做我需要的,但我有一个非常困难的时间,弄清楚如何测试我在做什么。我使用守护茉莉花运行茉莉花specs使用PhantomJS。
这里是(相关)html: <html id="ng-app" ng-app="app"> <div id="directive-element" class="directive-element"> </div> </html> javascript(在coffeescript)看起来像: window.Project = App: angular.module('app',[]) Directive: {} Project.Directive.DirectiveElement = -> restrict: 'C' link: (scope,element,attrs) -> element.html 'hello world' Project.App.directive 'directiveElement',Project.Directive.DirectiveElement 上面的代码正是它打算做什么。测试是问题。我不能让他们工作。这是我试过的一件事。发布这个主要只是开始谈话的地方。 describe 'App.Directive.DirectiveElement',-> it 'updates directive-element',-> inject ($compile,$rootScope) -> element = $compile('<div id="app" ng-app="app"><div id="directive'element" class="directive-element"></div></div>') expect(element.text()).toEqual('hello world') 另外,我是新的AngularJS,所以如果有任何关于命名空间,模块等的任何最佳实践,我不跟踪,指导将不胜感激。 如何获得测试这个工作?
Here’s how alert directive is tested in angular-ui/bootstrap。
Here’s another simple set of tests,for the buttons directive. 这里有一些提示: >确保告诉测试运行器你在beforeEach(module(‘myModule’))测试的模块。 您可以在the bootstrap repo中找到不同复杂度的指令的测试。只需查看src / {directiveName} / test /。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |