【问题标题】:How to unit test ui-route in angular js?如何在 Angular js 中对 ui-route 进行单元测试?
【发布时间】:2014-12-27 10:09:25
【问题描述】:

我有一个构建这种 html 的简单指令:

<div class='snapshots-feeds-toggle-box'>
    <button ui-sref='feeds' class='state-toggle-btn' ui-sref-active='active-state'>Feeds</button>
    <button ui-sref='snapshots' class='state-toggle-btn' ui-sref-active='active-state'>Snapshots</button>
</div>

我想对它(karma+jasmine)进行单元测试,如下所示:

我只想检查我是否设置了提要状态,按钮是否处于“活动状态”,我应该如何处理:

变量作用域,编译;

beforeEach(module('feedsSnapshotsApp'));
beforeEach(module('directives'));

beforeEach(inject(function ($rootScope,$compile) {
    scope = $rootScope.$new();
    compile = $compile;
...
   scope.state = 'feeds' //?
it('should check if state is active',function(){
     //What is the check that i can do here?
})   

【问题讨论】:

    标签: angularjs unit-testing jasmine karma-runner


    【解决方案1】:

    再次阅读您的问题:“如何在 Angular js 中对 ui-route 进行单元测试”

    你为什么要这样做?您想要测试的行为已经在ui-router 中进行了测试,因此您无需重新测试已经在其他地方测试过的东西。专注于你的指令必须提供和测试它。

    【讨论】:

    • 这不能回答问题,例如在我的情况下,我使用的指令取决于“ui-router”(状态),我遇到了我无法解决的问题点击带有ui-sref的div,点击时状态不会改变!
    • 回答他的问题,而不是你的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    相关资源
    最近更新 更多