【发布时间】:2017-03-30 22:15:05
【问题描述】:
您好,我一直在尝试在我的控制器中对基本功能进行单元测试,但是在设置单元测试时我似乎无法连接。
错误:[$injector:modulerr] 无法实例化模块 myApp 由于: [$injector:nomod] 模块“myApp”不可用!您要么拼错了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。
这是我的控制器:
var myApp = angular.module("myApp", []);
myApp.controller('studentController', function($scope,$route,$routeParams,$http,$location){
//Get all students
$scope.getStudents = function(){
$http.get('/api/student/').then(function(response){
$scope.students = response.data;
});
};
和我的测试:
describe("studentController", function () {
beforeEach(module('myApp'));
var $controller;
beforeEach(inject(function (_$controller_){
$controller = _$controller_;
}))
describe("studentController", function(){
it("should get student data", function (){
var $scope = {};
$scope.getStudents();
expect($scope.students.length).toBe(15)
})
})
});
我已将这两个文件与 angular-mocks.js 一起包含在 jasmine html 文件中
任何帮助将不胜感激
【问题讨论】:
标签: javascript angularjs function unit-testing