首页 > 解决方案 > 为什么模板没有在测试中编译?

问题描述

我为我的控制器写了一个规范。Angular 模块 ngCountdownRibbon 具有向文档正文添加带有计数器的功能区的逻辑。在 getRibbonDate 函数中,我想访问此计算值并在测试中检查它们(html 元素的内部文本)。但不知何故,当我尝试获取它时它没有被编译。我怎样才能让这个规范工作?

期望的行为

附加在文档正文中的编译代码应为:

  <a ng-href="http://amzn.com/w/ZWFNUL8AGNLP" class="ribbon-container ng-scope" 
     target="_blank" href="http://amzn.com/w/ZWFNUL8AGNLP">
    <span class="ribbon ribbon_left" ng-class="ngCountdownRibbon.ribbonClass"> 
      <span>
        <ng-pluralize
            count="ngCountdownRibbon.ribbonDays"
            when="{'0': 'Event has come', 'one': '1 day left', 'other': '{} days left'}"
            <="" 
            ng-pluralize="">1 day left
        </ng-pluralize>
      </span>
    </span>
  </a>

我现在在编译代码中得到什么

LOG:
 <a ng-href="{{ngCountdownRibbon.ribbonLink}}" class="ribbon-container ng-scope" 
       target="_blank">
    <span class="ribbon" ng-class="ngCountdownRibbon.ribbonClass">
      <span>
        <ng-pluralize
          count="ngCountdownRibbon.ribbonDays"
          when="{'0': 'Event has come', 'one': '1 day left', 'other': '{} days left'}"
          <="" ng-pluralize="">
        </ng-pluralize>
      </span>
    </span>
</a>

重现的最短方法是 fork repo并从分支 init-tests 运行“npm test”命令

标签: angularjsunit-testingkarma-runner

解决方案


推荐阅读