W3C 通知覆盖范围
W3C Notification Coverage
由于 W3C 通知不适用于 PhantomJS,我无法将代码覆盖率提高到 100%。我有以下功能:
function requirespermission(overwrite){
if(overwrite || (typeof Notification !== 'undefined' && Notification.permission === 'granted'))
{
return true;
}
else if(!overwrite || typeof Notification !== 'undefined'){
Notification.requestPermission();
}
return false;
}
我的测试如下:
it('should be able to get permission', function(){
notificationservice.requirespermission(true);
});
it('should be able to not get permission', function(){
notificationservice.requirespermission(false);
});
但无论我做什么,else 函数的条件覆盖率都保持在 2/4(这是有道理的,但我必须实现跨浏览器支持的检查)。我使用以下工具:
- 业力+茉莉花进行测试
- 业力覆盖
- PhantomJS 作为单元测试浏览器
- 科伯图拉 饰 记者
- (詹金斯 饰 CI)
如何让 else 函数通过代码覆盖率测试?
我通过使用 Notify.js 对通知使用包装器解决了这个问题。现在的代码是:
function requirespermission(overwrite){
if(!Notify.needsPermission || overwrite)
{
return true;
}
else if(Notify.isSupported()){
Notify.requestPermission();
}
return false;
}
和测试:
it('should be able to not get permission', function(){
notificationservice.requirespermission(true);
});
it('should be able to not get permission', function(){
spyOn(Notify, 'isSupported').and.returnValue(true);
notificationservice.requirespermission(false);
});
it('should handle not-supported', function(){
spyOn(Notify, 'isSupported').and.returnValue(false);
notificationservice.requirespermission(false);
});
相关文章:
- 在循环中分配json值时,值被覆盖
- 正在全局范围中查找JavaScript函数
- Sonarqube通用覆盖范围-结果在哪里
- Sonarqube不会从LCOV检索我的JavaScript覆盖范围
- WebDriver Selenium:Javascript代码覆盖范围,无需服务器访问
- W3C 通知覆盖范围
- Javascript 覆盖回调的范围
- 茉莉花+伊斯坦布尔覆盖范围不起作用
- 可变范围,不要覆盖
- 如何在不覆盖父范围的情况下将参数传递给指令
- Javascript 闭包 - 全局范围内被覆盖函数的行为
- IntelliJ的服务器端JS覆盖范围
- javascript函数范围和覆盖
- 检测标记是否在谷歌地图上的圆圈覆盖范围内(Javascript API V3)
- 删除或覆盖Restangular中限定范围配置的请求拦截器
- 原型覆盖范围问题
- 使用伊斯坦布尔的nightwatch.js代码覆盖范围
- 扩展/覆盖 jQuery 对象文字方法 - 超出范围的问题
- “ng-repeat”上的自定义过滤器确实会覆盖范围
- 当使用Karma和Istanbul时,从覆盖范围中排除文件