Angularjs 使用mocha编写单元测试时未定义角度
我似乎找不到解决我问题的答案,我已经被困了一天,如果有任何答案,我将不胜感激。我正在尝试为我的控制器编写单元测试,当我编写:mocha——recursive./tests时 我得到这个错误: ReferenceError:未定义角度 在C:\wamp64\www\music sp\ang\genre\genre.controller.js:4:5 反对。(C:\wamp64\www\music sp\ang\genre\genre.controller.js:34:3) GenreController.js:Angularjs 使用mocha编写单元测试时未定义角度,angularjs,mocha.js,Angularjs,Mocha.js,我似乎找不到解决我问题的答案,我已经被困了一天,如果有任何答案,我将不胜感激。我正在尝试为我的控制器编写单元测试,当我编写:mocha——recursive./tests时 我得到这个错误: ReferenceError:未定义角度 在C:\wamp64\www\music sp\ang\genre\genre.controller.js:4:5 反对。(C:\wamp64\www\music sp\ang\genre\genre.controller.js:34:3) GenreControl
(function () {
'use strict';
angular.module('app').controller('GenreController', GenreController);
GenreController.$inject = ['$location', 'AuthenticationService', 'FlashService', 'UniversalService', '$scope'];
function GenreController($location, AuthenticationService, FlashService, UniversalService, $scope) {
var vm = this;
vm.allgenres = [];
$scope.currentSong = function(url) {
$scope.PlayerUrl = $sce.trustAsResourceUrl(url + '?enablejsapi=1&modestbranding=1&showinfo=0&controls=0&autoplay=1');
};
loadAllGenres();
$scope.loadArtists = function(genreId){
UniversalService.UpdateGenreId(genreId);
}
function loadAllGenres() {
UniversalService.GetAllGenres()
.then(function (genre) {
vm.allgenres = genre.Results;
});
}
}
这是我的项目文件结构图,我正在测试文件夹中编写测试
您是在nodejs中运行测试,还是通过浏览器运行测试?不管怎样,您似乎没有将angular.js库本身包含到您的测试中,您必须做什么。不仅仅是angular.js,你需要包括所有你想测试的应用程序。我通过mochaYeah运行它们,好的。但摩卡只是一个测试框架。我认为你应该阅读有关karma test runner的文章,并将其用于测试。因为既然你们编写了浏览器应用程序,你们最好在浏览器中测试它。好的,我会这么做:)