Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角定向茉莉花试验_Javascript_Jquery_Html_Angularjs_Jasmine - Fatal编程技术网

Javascript 角定向茉莉花试验

Javascript 角定向茉莉花试验,javascript,jquery,html,angularjs,jasmine,Javascript,Jquery,Html,Angularjs,Jasmine,我试图测试一个角度指令,它根据按键事件返回true或false。我在一个UI中使用该指令,该UI在输入标记中具有ng model。HTML代码如下所示: <div class="inline-middle-align set-margin "> <input class="form-control" type="text" ng-model="addedRP.Offset" min="0" max="999" maxlength="3" style="width: 65

我试图测试一个角度指令,它根据按键事件返回
true
false
。我在一个UI中使用该指令,该UI在输入标记中具有
ng model
。HTML代码如下所示:

<div class="inline-middle-align set-margin ">
    <input class="form-control" type="text" ng-model="addedRP.Offset" min="0" max="999" maxlength="3" style="width: 65px" placeholder="Offset" rp-Offset-Input-Validation-Directive required/>
</div>

指令代码为:

angular.module('helperModule')
.directive('rpOffsetInputValidationDirective', function (e) {
    'use strict';
    return {
        require: 'ngModel',
        link: function (scope, elem) {

            elem.on('keypress', function (e) {
                if (e.which !== 8 && e.which !== 0 && (e.which < 48 || e.which > 57)) {
                    return false;
                }
            });
        }
    };
});
angular.module('helperModule'))
.directive('rpOffsetInputValidationDirective',函数(e){
"严格使用",;
返回{
要求:'ngModel',
链接:功能(范围、要素){
要素开启(“按键”,功能(e){
如果(e.which!==8&&e.which!==0&&e.which<48 | e.which>57)){
返回false;
}
});
}
};
});
我已经为它写了一个测试,但它不起作用

it('should return true called on a keypress', function () {
    $rootScope.happy = 10;              
    var ele = angular.element("<input ng-model='happy' rp-offset-input-validation-directive/>");
    element = $compile(ele)($rootScope);
    $rootScope.$digest();
    $rootScope.e = $.Event('keypress');
    e.which = 50;
    $(ele[0]).trigger(e);
    expect($rootScope.happy).toBe(2);
});
it('在按键时应返回true',函数(){
$rootScope.happy=10;
var ele=角度元素(“”);
元素=$compile(ele)($rootScope);
$rootScope.$digest();
$rootScope.e=$.Event('keypress');
e、 其中=50;
$(ele[0])。触发器(e);
期望($rootScope.happy);
});

嗨,乔贝!你需要什么?