【发布时间】:2016-03-25 06:56:15
【问题描述】:
我有一个看起来像这样的指令:
myApp.directive('inputCheck', function(){
return{
restrict: 'A',
link: function(scope, element){
element.keydown(function(event){
return event.which == 46
});
}
}
});
上面检查用户是否点击了键盘上的delete键。我可以使用以下方法为其设置 Jasmine 单元测试:
describe('inputCheckTest', function(){
it('should return true when delete key is pressed', function(){
var scope = inputCheckElement.scope();
var event = jQuery.Event('keydown');
event.which = 46;
inputCheckElement.trigger(event);
// How do I check that the returned value from the link function is true?
});
});
在这个单元测试中,你如何写一个关于返回值的真实检查?
【问题讨论】:
-
您认为谁会从事件处理程序中获得回报?既然没人会看到,那回报有什么关系吗?