可以在单元测试中调试控制器吗?
实际上,我可以调试Spec.js文件。
这是我的控制器代码
angular.module('app', [])
.controller('PasswordController', function PasswordController($scope) {
$scope.password = '';
$scope.grade = function () {
var size = $scope.password.length;
if (size > 8) {
$scope.strength = 'strong';
} else if (size > 3) {
$scope.strength = 'medium';
} else {
$scope.strength = 'weak';
}
};
});
但是当我在Chrome中打开控制器时,它会显示以下代码
var __cov_8V5V73zRqzgMjN4umkcw8g = (Function('return this'))();
if (!__cov_8V5V73zRqzgMjN4umkcw8g.__coverage__) {__cov_8V5V73zRqzgMjN4umkcw8g.__coverage__ = {}; }
__cov_8V5V73zRqzgMjN4umkcw8g = __cov_8V5V73zRqzgMjN4umkcw8g.__coverage__;
if (! (__cov_8V5V73zRqzgMjN4umkcw8g['D:/workspace/staging/WL1/OTP/src/Server/WebApp/app/features/configureDatasets/DeleteThis.js'])) {
__cov_8V5V73zRqzgMjN4umkcw8g['D:/workspace/staging/WL1/OTP/src/Server/WebApp/app/features/configureDatasets/DeleteThis.js'] = {"path":"D:/workspace/staging/WL1/OTP/src/Server/WebApp/app/features/configureDatasets/DeleteThis.js","s":{"1":0,"2":0,"3":0,"4":1,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0},"b":{"1":[0,0],"2":[0,0]},"f":{"1":0,"2":0},"fnMap":{"1":{"name":"PasswordController","line":18,"loc":{"start":{"line":18,"column":34},"end":{"line":18,"column":70}}},"2":{"name":"grade","line":25,"loc":{"start":{"line":25,"column":4},"end":{"line":25,"column":21}}}},"statementMap":{"1":{"start":{"line":17,"column":0},"end":{"line":35,"column":3}},"2":{"start":{"line":22,"column":4},"end":{"line":22,"column":18}},"3":{"start":{"line":23,"column":4},"end":{"line":23,"column":21}},"4":{"start":{"line":25,"column":4},"end":{"line":34,"column":5}},"5":{"start":{"line":26,"column":8},"end":{"line":26,"column":38}},"6":{"start":{"line":27,"column":8},"end":{"line":33,"column":9}},"7":{"start":{"line":28,"column":12},"end":{"line":28,"column":35}},"8":{"start":{"line":29,"column":15},"end":{"line":33,"column":9}},"9":{"start":{"line":30,"column":12},"end":{"line":30,"column":35}},"10":{"start":{"line":32,"column":12},"end":{"line":32,"column":33}}},"branchMap":{"1":{"line":27,"type":"if","locations":[{"start":{"line":27,"column":8},"end":{"line":27,"column":8}},{"start":{"line":27,"column":8},"end":{"line":27,"column":8}}]},"2":{"line":29,"type":"if","locations":[{"start":{"line":29,"column":15},"end":{"line":29,"column":15}},{"start":{"line":29,"column":15},"end":{"line":29,"column":15}}]}}};
}
__cov_8V5V73zRqzgMjN4umkcw8g = __cov_8V5V73zRqzgMjN4umkcw8g['D:/workspace/staging/WL1/OTP/src/Server/WebApp/app/features/configureDatasets/DeleteThis.js'];
__cov_8V5V73zRqzgMjN4umkcw8g.s['1']++;angular.module('app',[]).controller('PasswordController',function PasswordController($scope) {__cov_8V5V73zRqzgMjN4umkcw8g.f['1']++;__cov_8V5V73zRqzgMjN4umkcw8g.s['2']++;var vm=this;__cov_8V5V73zRqzgMjN4umkcw8g.s['3']++;vm.password='';function grade(){__cov_8V5V73zRqzgMjN4umkcw8g.f['2']++;__cov_8V5V73zRqzgMjN4umkcw8g.s['5']++;var size=vm.password.length;__cov_8V5V73zRqzgMjN4umkcw8g.s['6']++;if(size>8){__cov_8V5V73zRqzgMjN4umkcw8g.b['1'][0]++;__cov_8V5V73zRqzgMjN4umkcw8g.s['7']++;vm.strength='strong';}else{__cov_8V5V73zRqzgMjN4umkcw8g.b['1'][1]++;__cov_8V5V73zRqzgMjN4umkcw8g.s['8']++;if(size>3){__cov_8V5V73zRqzgMjN4umkcw8g.b['2'][0]++;__cov_8V5V73zRqzgMjN4umkcw8g.s['9']++;vm.strength='medium';}else{__cov_8V5V73zRqzgMjN4umkcw8g.b['2'][1]++;__cov_8V5V73zRqzgMjN4umkcw8g.s['10']++;vm.strength='weak';}}};});
如何在单元测试中调试控制器代码?
答案 0 :(得分:0)
从我所看到的可能是你正在使用某种覆盖工具(可能是Instambul?)
如果是这种情况,只需创建一个指向原始JS源的单独SpecRunner,您就可以在浏览器中进行调试。
让我知道这是否有意义