1

我正在为显示微调器的角度指令编写一些茉莉花测试。我的指令看起来像:

定义([
    “应用程序”,
    “旋转”
], 功能(
    应用程序,
    微调器
    ){
    '使用严格';

    返回应用程序
        .directive('处理', function() {

            返回 {
                限制:'E',
                嵌入:假,
                范围: {
                    显示:'=显示',
                    消息:'=消息'
                },

                templateUrl: 'directives/spin/processing.html',
                链接:功能(范围,元素,属性){
                    var 微调器 = 新微调器({
                        lines: 17, // 要绘制的线数
                        length: 40, // 每行的长度
                        width: 10, // 线条粗细
                        radius: 60, // 内圆的半径
                        corners: 1, // 角圆度 (0..1)
                        rotate: 0, // 旋转偏移
                        direction: 1, // 1: 顺时针, -1: 逆时针
                        color: '#000', // #rgb 或 #rrggbb 或颜色数组
                        speed: 1, // 每秒轮数
                        trail: 60, // 余辉百分比
                        shadow: true, // 是否渲染阴影
                        hwaccel: false, // 是否使用硬件加速
                        className: 'spinner', // 分配给微调器的 CSS 类
                        zIndex: 2e9, // z-index(默认为 2000000000)
                        top: 'auto', // 相对于父级的顶部位置,单位 px
                        left: 'auto' // 相对于父级的左侧位置,单位 px
                    })。旋转();
                    var loadingContainer = element[0].querySelectorAll('.processing-spinner-container')[0];
                    loadingContainer.appendChild(spinner.el);

                }
            };


        });
});

我的模板如下所示: <div><div ng-show="show" class="processing-spinner-container"></div></div>

现在,当我想做一个 jasmine 单元测试,测试 ng-show 时,我有这样的东西

           it('当 ngShow 为真时应该在那里', inject(function($rootScope, $compile) {
                $scope = $rootScope.$new();
                $scope.show =真;
                var element = $compile('<processing>\</processing>')($scope);
                $scope.$apply();
                var spinnerContainer = element[0].querySelector('.processing-spinner-container');
                期望(spinnerContainer.classList.contains('ng-hide')).toBe(false);
            }));

但是,此测试失败。ng-hide即使我已将 $scope.show 设置为 true,它仍然具有该类。

4

0 回答 0